Skip to content

🐛 Bug / Feature Request: inputModel = true fails on relations to join models with composite IDs #52

@tsegreto

Description

@tsegreto

🐛 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 memberships

Minimal 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 generate

Expected behavior

One of the following would be ideal:

  1. Support composite IDs / compound uniques for relation connect / disconnect shapes in InputModels (generate a schema compatible with Prisma’s compound-unique connect format), or

  2. If composite IDs aren’t supported, skip or disable connect/disconnect generation for such relations (with a documented option), or

  3. 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 memberships

Why 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 id to 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
  • If composite/compound is present, generate connect / disconnect schemas that accept a compound “where” object (as Prisma does), or allow a config option to select which unique constraint to use.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions