Hello! I am new to slack so excuse any formatting ...
# orm-help
v
Hello! I am new to slack so excuse any formatting issues. I am having difficulties writing my schema. Very new to SQL and relational databases (I am a long time mongodb user) 🙂 Any kind of help is appreciated.
model TestUser {
id String @id @default(cuid()) @unique
name String
madeReviews Review[]
receivedReviews Review[]
}
model TestReview {
id String @id @default(cuid()) @unique
author TestUser @relation(_fields_: [authorId], _references_: [id])
authorId String
receiver TestUser @relation(_fields_: [receiverId], _references_: [id])
receiverId String
rating Int
comment String
}
I basically just want to have a user that can make and get reviews.
👀 1
a
Hey Viggo! Welcome to the Prisma community 👋. What trouble specifically are you having?
v
Hello! I am getting ambiguous relation errors.
a
Since you have to relation fields between the same model (receiver -> receivedReviews, author -> madeReviews), you need to disambiguate the relations by giving them unique names.
Copy code
model TestUser {
  id String @id @default(cuid()) @unique
  name String
  madeReviews Review[]     @relation('made')
  receivedReviews Review[] @relation('received')
}
model TestReview {
  id String @id @default(cuid()) @unique
  author TestUser @relation(name: 'made', fields: [authorId], references: [id])
  authorId String
  receiver TestUser @relation(name: 'received', fields: [receiverId], references: [id])
  receiverId String
  rating Int
  comment String
}
You can read more here in our docs.