[프리스마] 일대다 관계.

3413 단어 Prismatech

코드


schema.prisma
model User {
  id      Int      @id @default(autoincrement())
  email   String   @unique
  name    String?
  role    Role     @default(USER)
  posts   Post[]
  profile Profile?
}

model Profile {
  id     Int    @id @default(autoincrement())
  bio    String
  user   User   @relation(fields: [userId], references: [id])
  userId Int
}

할 일


모 모델에 추가


posts   Post[]

서브모델에 추가


user   User   @relation(fields: [userId], references: [id])
userId Int
하위 모형의useerId는 부모 모형의 id에 해당하기 때문이다
@relation(fields: [userId], references: [id])
되다

참고 자료


https://www.prisma.io/docs/concepts/components/prisma-schema/data-model

좋은 웹페이지 즐겨찾기