Hi, is there a way to require one of two relation...
# orm-help
y
Hi, is there a way to require one of two relations? In the case below, Person must relate either to a Doctor or to a Lawyer.
Copy code
model Person {
  id     Int     @id @default(autoincrement())
  doctor Doctor?
  lawyer Lawyer?
}

model Doctor {
  id     Int    @id
  person Person @relation(fields: [id], references: [id])
}

model Lawyer {
  id     Int    @id
  person Person @relation(fields: [id], references: [id])
}
a
I think your most common solution is going to be to require that at the validation level with a library like Yup, rather than at the schema definition level
another solution would be to use single table inheritance, but it looks like that isn't supported in prisma yet. (And honestly, that's a solution that often causes more problems than it solves.)
y
@Austin Zentz Thank for your response! I agree with you regarding single table inheritance. Good luck!