You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: join-table DB interface uses physical A/B columns (Codec.Encoded)
Implicit M:N join tables were typed in the Kysely DB interface as
Schema.Schema.Type<typeof JoinTable> — the DECODED shape, whose keys are the
semantic *_id names. But Kysely uses DB-interface field names as literal SQL
column identifiers, and an implicit M:N table's physical Postgres columns are
A/B. So `db.selectFrom('_x').where('_x.product_id', ...)` emitted `WHERE
product_id` against an A/B-only table → runtime SQL error.
Emit Schema.Codec.Encoded<typeof JoinTable> instead — the ENCODED shape with
physical A/B keys, carrying the branded columnType values so joins stay
type-safe against the parent table's branded id. The semantic-name mapping
stays only in the schema's Schema.encodeKeys (decode side). Regular model
tables are unchanged.
Tests: unit (encode→{A,B}, decode→{product_id,...}, DB-entry string match) +
pglite integration running the exact previously-broken query
`where('_product_tags.A', '=', productId)` against a real A/B table with
branded values.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Prisma stores `A`/`B` columns; we emit semantic snake_case fields on the struct, then map them to the DB columns with a struct-level `.pipe(Schema.encodeKeys({ <model_a>_id: "A", <model_b>_id: "B" }))`. FK columns are `columnType(Id, Id, Schema.Never)` — insertable (you supply both keys when linking) but read-only on update (composite-PK rows are inserted/deleted, not updated). Join tables get NO branded ID (composite key).
89
89
90
+
The `DB`-interface entry for a join table uses `Schema.Codec.Encoded<typeof JoinTable>` (the **encoded**`A`/`B` shape), NOT `Schema.Schema.Type` — Kysely uses DB field names as literal SQL identifiers, and the physical columns are `A`/`B`. The semantic `*_id` names exist only on the decode side (`Schema.decode` output). Regular model tables still use `Schema.Schema.Type<typeof Model>`.
91
+
90
92
## UUID detection
91
93
92
94
`isUuidField()` in `src/prisma/type.ts`, priority order:
0 commit comments