Skip to content

One-to-many relationship #2236

Answered by ryands17
Rizialdi asked this question in Q&A
Apr 20, 2020 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

Hey @Rizialdi 👋
You had an issue in your schema, the @relation directive is not required on the many side of the relation while using 1-M relations

I have updated the schema here:

model Message {
  id        String   @default(cuid()) @id
  text      String
  sentBy    User?    @relation(fields: [sentById], references: [id])
  sentById  String?  @map("sentBy")
  channel   Channel? @relation(fields: [channelId], references: [id])
  channelId String?  @map("channel")
  createdAt DateTime @default(now())
}

model Channel {
  id        String    @default(cuid()) @id
  users     User[]    @relation(references: [id])
  messages  Message[]
  createdAt DateTime  @default(now())
}

model User {
  id

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Rizialdi
Comment options

Answer selected by Rizialdi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants