Skip to content

Instantly share code, notes, and snippets.

@ultrox
Last active June 10, 2020 10:40
Show Gist options
  • Save ultrox/3164ae560ee3c30689b36011ecf96792 to your computer and use it in GitHub Desktop.
Save ultrox/3164ae560ee3c30689b36011ecf96792 to your computer and use it in GitHub Desktop.
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

Relation 1-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment