P
Prisma•5mo ago
Ryan Prior

Contacts: error combining many-to-one with one-to-one on the same models

I'm just getting started modeling with Prisma and quickly hit a case I can't find help for in the docs. I want a Person to be able to have any number of Contacts, but exactly one primary Contact. My incorrect model looks like this:
model Contact {
id Int @id @default(autoincrement())
email String
personId Int
person Person @relation("PersonContact")
}

model Person {
id Int @id @default(autoincrement())
contactId Int
primaryContact Contact @relation("PersonPrimaryContact")
contacts Contact[] @relation("PersonContact")
}
model Contact {
id Int @id @default(autoincrement())
email String
personId Int
person Person @relation("PersonContact")
}

model Person {
id Int @id @default(autoincrement())
contactId Int
primaryContact Contact @relation("PersonPrimaryContact")
contacts Contact[] @relation("PersonContact")
}
If I remove the primaryContact field, this validates fine, but it's giving confusing errors with the primary contact, saying that model Contact lacks a relation back to Person. This is clearly not the case. What's wrong with my approach, and how would you proceed?
2 Replies
thai
thai•5mo ago
Did you fix this? I also run into similar problems with unintuitive error messages...
Ryan Prior
Ryan PriorOP•5mo ago
I have not fixed it yet. I did find some links in the Prisma docs to other similar libraries, so I'm trying some other options for now. Might take a second run at Prisma if I find a good modeling tutorial that covers this type of use case 😄
Want results from more Discord servers?
Add your server