model User {
id Int @id @default(autoincrement())
email String @unique
role Role // normal Relation field
profile Profile? // Relation field part of 0-1 relation
}
model Profile {
id Int @id @default(autoincrement())
title String
author User @relation(fields: [authorId], references: [id]) // Anotated Relation field
authorId Int // relation scalar field (used in the `@relation` attribute above)
}
- 2 Affected field in
- @relation needs to be only on one of them
- relation scalar field is FK on underlying DB, its always where @relation is.
- both be optional or both be required
-
"a user can have zero or one profiles" (because the profile field is optional on User)
-
"a profile must always be connected to one user"