Skip to content

Commit aae6a61

Browse files
committed
test(sql-orm-client): integration parity for arrow-path M:N include
Add a real emitted PSL fixture (mn-psl-arrow-path) authoring a Post <-> Tag many-to-many over a relation-field-less PostTag junction via the quoted arrow-path through: form, e.g. tags Tag[] @relation(through: "id -> PostTag.postId -> PostTag.tagId -> Tag.id") with the mirror-imaged path on Tag.posts. The resolver builds the through descriptor straight from the named columns and lowers both ends to cardinality: 'N:M' + through over post_tags -- the same runtime-consumable shape the authored-junction (mn-psl-through) and implicit (mn-psl-implicit) forms emit. Wire the fixture into the sql-orm-client emit chain so fixtures:check regen covers it, and add a PGlite integration parity test that drives db.orm.Post.include('tags') over the arrow-path M:N -- whole-row toEqual, explicit .select() plus one implicit-selection readback -- proving the column-based arrow-path contract drives the ORM include end-to-end. Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
1 parent 1c29677 commit aae6a61

6 files changed

Lines changed: 845 additions & 1 deletion

File tree

packages/3-extensions/sql-orm-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"description": "ORM client for Prisma Next — fluent, type-safe model collections",
88
"scripts": {
99
"build": "tsdown",
10-
"emit": "cd ../../../test/integration && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/polymorphism/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/junction-namespaces/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/execution-defaulted-tags/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/mn-psl/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/mn-psl-through/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/disambiguated-1n-inverse/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/self-ref-mn-through/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/mn-psl-implicit/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/mn-psl-implicit/prisma-next.config.sqlite.ts && cp test/sql-orm-client/fixtures/generated/contract.json test/sql-orm-client/fixtures/generated/contract.d.ts ../../packages/3-extensions/sql-orm-client/test/fixtures/generated/ && cp test/sql-orm-client/fixtures/junction-namespaces/generated/contract.json test/sql-orm-client/fixtures/junction-namespaces/generated/contract.d.ts ../../packages/3-extensions/sql-orm-client/test/fixtures/junction-namespaces/generated/ && cd ../../packages/3-extensions/sql-orm-client && node scripts/strip-pgvector-fixture.mjs test/fixtures/generated/contract.d.ts",
10+
"emit": "cd ../../../test/integration && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/polymorphism/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/junction-namespaces/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/execution-defaulted-tags/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/mn-psl/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/mn-psl-through/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/disambiguated-1n-inverse/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/self-ref-mn-through/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/mn-psl-implicit/prisma-next.config.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/mn-psl-implicit/prisma-next.config.sqlite.ts && node ../../packages/1-framework/3-tooling/cli/dist/cli.js contract emit --config test/sql-orm-client/fixtures/mn-psl-arrow-path/prisma-next.config.ts && cp test/sql-orm-client/fixtures/generated/contract.json test/sql-orm-client/fixtures/generated/contract.d.ts ../../packages/3-extensions/sql-orm-client/test/fixtures/generated/ && cp test/sql-orm-client/fixtures/junction-namespaces/generated/contract.json test/sql-orm-client/fixtures/junction-namespaces/generated/contract.d.ts ../../packages/3-extensions/sql-orm-client/test/fixtures/junction-namespaces/generated/ && cd ../../packages/3-extensions/sql-orm-client && node scripts/strip-pgvector-fixture.mjs test/fixtures/generated/contract.d.ts",
1111
"emit:check": "pnpm emit && git diff --exit-code test/fixtures/generated/ test/fixtures/junction-namespaces/generated/",
1212
"test": "vitest run",
1313
"test:coverage": "vitest run --coverage",
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Real emitted fixture for the sql-orm-client arrow-path many-to-many parity
2+
// test — the `Post ↔ Tag` relation authored over a relation-field-less
3+
// junction via the quoted arrow-path `through:` form.
4+
//
5+
// `PostTag` carries the scalar join columns `postId` / `tagId` plus a composite
6+
// `@@id`, but NO `post` / `tag` relation fields. The slice-2 relation-field
7+
// junction recognition can't fire (there are no relation fields to walk), so
8+
// the navigable M:N is declared on the terminal models with the quoted
9+
// arrow-path that names the join columns directly:
10+
//
11+
// tags Tag[] @relation(through: "id -> PostTag.postId -> PostTag.tagId -> Tag.id")
12+
// posts Post[] @relation(through: "id -> PostTag.tagId -> PostTag.postId -> Post.id")
13+
//
14+
// Path shape: `<localKey> -> <Junction.nearCol> -> <Junction.farCol> -> <targetKey>`.
15+
// Both ends carry their own mirror-imaged arrow-path (the junction has no
16+
// relation fields from which to infer an inverse). The resolver builds the
17+
// `through` descriptor straight from the named columns, lowering both ends to a
18+
// navigable `cardinality: 'N:M'` relation with a populated `through` descriptor
19+
// over `post_tags` — the same runtime-consumable shape an authored junction or
20+
// implicit M:N emits — so the M:N ORM `include` drives through a PSL contract
21+
// authored with the column-based arrow-path.
22+
//
23+
// `@@map` pins the storage tables (`posts` / `tags` / `post_tags`) and columns
24+
// (`post_id` / `tag_id`) so the integration schema setup and the emitted
25+
// `through` descriptor agree on names.
26+
27+
model Post {
28+
id Int @id
29+
title String
30+
31+
tags Tag[] @relation(through: "id -> PostTag.postId -> PostTag.tagId -> Tag.id")
32+
33+
@@map("posts")
34+
}
35+
36+
model Tag {
37+
id String @id
38+
label String @unique
39+
40+
posts Post[] @relation(through: "id -> PostTag.tagId -> PostTag.postId -> Post.id")
41+
42+
@@map("tags")
43+
}
44+
45+
model PostTag {
46+
postId Int @map("post_id")
47+
tagId String @map("tag_id")
48+
49+
@@id([postId, tagId])
50+
@@map("post_tags")
51+
}

test/integration/test/sql-orm-client/fixtures/mn-psl-arrow-path/generated/contract.d.ts

Lines changed: 288 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)