TML-2782: thread variant name through orderBy for MTI variant fields#740
TML-2782: thread variant name through orderBy for MTI variant fields#740tensordreams wants to merge 4 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis PR extends ChangesVariant-aware orderBy for MTI polymorphic collections
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
size-limit report 📦
|
@prisma-next/extension-author-tools
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/middleware-cache
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/extension-postgis
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/extension-supabase
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/cli-telemetry
@prisma-next/emitter
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
f3a6796 to
0b3dff4
Compare
…ant fields orderBy() called createModelAccessor without the selected variantName, so the accessor resolved every selector field against the base table only. For an MTI variant a variant-owned column (e.g. priority on the joined variant table) was unreachable, dropping the column and breaking the sort. Mirror the where()/first() pattern: thread this.state.variantName through createModelAccessor and make the selector callback param VariantAwareModelAccessor, bridged at the accessor boundary with the same justified blindCast. The no-variant path is byte-for-byte unchanged. The include-refinement orderBy shares this call site, so r.variant(X).orderBy(...) inside an include is fixed too. Tests: unit (variant-aware ColumnRef resolution + no-variant regression guard), type tests (priority type-checks under variant(Feature), rejected without a variant), and PGlite integration (root + include-refinement variant orderBy, whole-shape toEqual asserting the order). Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
…By variant tests AsyncIterableResult#then already collects, so awaiting the orderBy terminal yields the array directly. Removes the trailing .toArray() from the three orderBy variant tests added by this PR. API-wide removal is tracked in TML-2848. Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
0b3dff4 to
fea89b5
Compare
What
Fixes TML-2782:
orderByon a variant-narrowed collection couldn't reference an MTI variant-specific column —db.orm.Task.variant('Feature').orderBy(o => o.priority.desc())threwCannot read properties of undefined, becauseorderBybuilt its accessor without the selectedvariantName, resolving fields against the base table only.How
The variant-aware machinery already exists (TML-2683's
where/firstfix):createModelAccessortakes an optionalvariantNameand resolves variant-owned fields to aColumnRefon the joined variant table. This PR threadsstate.variantNamethroughorderBy's accessor construction and gives the selector callback the sameVariantAwareModelAccessor<…, State['variantName']>type treatment — an exact mirror of thewherepath, including the justified boundary cast (net bare-cast delta: −1). The include-refinementorderBy(r => r.variant('X').orderBy(…)) shares the same call site and is fixed by the same change; no query-lowering changes were needed (the variant join was already emitted).The no-variant path is byte-for-byte unchanged (optional param, truthiness-keyed) and pinned by a regression test.
Verification
Tests-first (RED→GREEN evidenced): 3 unit tests (variant column resolves to
ColumnRef.of('features','priority'); base fields stay base-qualified; no-variant unchanged), 4 type tests (accept undervariant('Feature')at root + include refinement; reject undervariant('Bug')and with no variant), 2 PGlite integration tests asserting the actual priority-descending order whole-shape under default selection. Gates: package typecheck + 521 tests, integration 8/8,lint:deps,lint:casts−1, DCO. Independently reviewed (pattern fidelity vswhere/first, regression guard, non-tautological tests): no findings.Scope: 1 src file + 3 test files. Adjacent known issues deliberately untouched: TML-2783 (select-leak), TML-2828 (variant relations on accessor).
Summary by CodeRabbit
Bug Fixes
orderBy()on variant-narrowed collections to correctly resolve variant-specific fields instead of throwing an error.Tests
Documentation
orderBy()variant-narrowing fix.