PrismaP
Prisma2y ago
3 replies
Anas Badran

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)
}
Was this page helpful?