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[]
}
0 Replies
No replies yetBe the first to reply to this messageJoin