[프리스마] 일대다 관계.
코드
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])
되다
참고 자료
Reference
이 문제에 관하여([프리스마] 일대다 관계.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/dev63/articles/4eb8a97854ec0d텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)