unique constraints

How to tell prisma that I want only one image with isPrimary set to true but also allow any number of images with isPrimary set to false for the same drugItem?
model Image {
id String @id @default(auto()) @map("_id") @db.ObjectId
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
publicID String @unique
width Int
height Int
url String
isPrimary Boolean @default(false)
drugItemID String? @db.ObjectId
drugItem DrugItem? @relation(fields: [drugItemID], references: [id], onDelete: Cascade)
}
model Image {
id String @id @default(auto()) @map("_id") @db.ObjectId
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
publicID String @unique
width Int
height Int
url String
isPrimary Boolean @default(false)
drugItemID String? @db.ObjectId
drugItem DrugItem? @relation(fields: [drugItemID], references: [id], onDelete: Cascade)
}
2 Replies
Dkyc
Dkyc2mo ago
this sounds like a job you need to do in your code
Anas Badran
Anas Badran2mo ago
I will do that in the code, but does prisma supports this constraint?
Want results from more Discord servers?
Add your server