I would like to implement this system

Subscription    <--->   ItemTypeA
---                     ---
itemTypeId              id
userId
type (= 'A')


Subscription    <--->   ItemTypeB
---                     ---
itemTypeId              id
userId
type (= 'B')


Subscription    <--->   ItemTypeC
---                     ---
itemTypeId              id
userId
type (= 'C')

In database :

| itemTypeId | userId    | type |
| ---------- | --------- | ---- |
|      1     |    12     |   A  |
|      1     |    12     |   B  |
|      2     |    12     |   B  |
|      1     |    55     |   C  |
|      1     |     4     |   C  |

I can’t find how to do it with Prisma

I tried this but Prisma complains about unique constraint names in namespace

model Subscription {
  user   User @relation(fields: [userId], references: [id])
  userId Int  @db.UnsignedInt

  itemTypA ItemTypeA?       @relation(fields: [itemTypeId], references: [id])
  itemTypB ItemTypeB?       @relation(fields: [itemTypeId], references: [id])
  itemTypC ItemTypeC?       @relation(fields: [itemTypeId], references: [id])
  itemTypeId   Int          @db.UnsignedInt

  @@unique([userId, itemTypeId])
  @@map("subscription")
}

Khám phá các thẻ bài đăng