-
Notifications
You must be signed in to change notification settings - Fork 15
Description
🐛 Bug / Feature Request: inputModel = true fails on relations to join models with composite IDs
Summary
When inputModel = true is enabled, prismabox generation fails if a relation points to an explicit join model that does not have a single scalar @id (e.g., it uses a composite primary key @@id([…])).
This seems like a generator limitation: prismabox InputModels appear to assume that related records can be identified with a single scalar ID for connect / disconnect.
Error
Unsupported ID type: Membership on model User in relation membershipsMinimal Reproduction (brief example)
Prisma schema
model User {
id String @id @default(uuid())
memberships Membership[]
}
model Team {
id String @id @default(uuid())
memberships Membership[]
}
// Explicit join model with composite primary key
model Membership {
userId String
teamId String
user User @relation(fields: [userId], references: [id])
team Team @relation(fields: [teamId], references: [id])
@@id([userId, teamId])
}Generator config
generator prismabox {
provider = "prismabox" // or the correct provider string
inputModel = true
}Command
prisma generateExpected behavior
One of the following would be ideal:
-
Support composite IDs / compound uniques for relation
connect/disconnectshapes in InputModels (generate a schema compatible with Prisma’s compound-uniqueconnectformat), or -
If composite IDs aren’t supported, skip or disable connect/disconnect generation for such relations (with a documented option), or
-
At minimum, fail with a clearer error message like:
inputModel=true requires the related model to have a single scalar @id field (composite @@id not supported yet)
Actual behavior
Generation fails with:
Unsupported ID type: Membership on model User in relation membershipsWhy this matters
Composite-key join tables are a common Prisma pattern. With inputModel = true, projects that model many-to-many relationships using explicit join models cannot generate InputModels unless they introduce a surrogate id.
Workarounds
- Add a surrogate scalar
idto the join model and keep a@@unique([userId, teamId]), or - Hide the relation from input generation (if supported), and manage join records through a dedicated endpoint/model, or
- Disable
inputModel.
Proposed implementation idea
When generating InputModels for relation fields, prismabox could:
-
Detect whether the related model is identified by:
- scalar
@id, or - composite
@@id, or - compound
@@unique
- scalar
-
If composite/compound is present, generate
connect/disconnectschemas that accept a compound “where” object (as Prisma does), or allow a config option to select which unique constraint to use.