ImNotGood
ImNotGood
PPrisma
Created by ImNotGood on 4/26/2024 in #help-and-questions
multiple relations to same table
Hi Ya'll! I am trying to figure out my schema. I have a PI table and a contact table. I want the PI to be able to have two contacts one public and one private but I am having trouble figuring out how these relations work. Any thoughts would be appreciated
model PI {
id String @id @default(cuid())
publicContactId String?
privateContactId String?

publicContact Contact? @relation("PublicContact", fields: [publicContactId], references: [id])
privateContact Contact? @relation("PrivateContact",fields: [privateContactId], references: [id])

@@index([publicContactId])
@@index([privateContactId])
}

model Contact {
id String @id @default(cuid())
name String?
email String?
phone String?
title String?

agreements Agreement[]
}
model PI {
id String @id @default(cuid())
publicContactId String?
privateContactId String?

publicContact Contact? @relation("PublicContact", fields: [publicContactId], references: [id])
privateContact Contact? @relation("PrivateContact",fields: [privateContactId], references: [id])

@@index([publicContactId])
@@index([privateContactId])
}

model Contact {
id String @id @default(cuid())
name String?
email String?
phone String?
title String?

agreements Agreement[]
}
2 replies