PrismaP
Prisma14mo ago
1 reply
Anas Badran

Enforce uniqueness on Json fields

How can I enforce uniqueness on the post model based on the values in the json fields.
here is the schema:
model Post {
  id           String        @id @default(cuid())
  title        String
  content      String
  collectionId String
  collection   Collection    @relation(fields: [collectionId], references: [id])
  metadata     PostMetadata? @relation(name: "PostMetadata")
  extraData    Json?         @db.JsonB
  tags         Tag[]         @relation(name: "PostTags")
}

the extraData fields json will look like:
{
surah: string:
verse: number
}

I don't want two records with same values to exist, like if there is record with these in the json field surah: "24", verse: 30, I don't want another to be created with same values
Was this page helpful?