Repository navigation
fix(orm): pass the model alias to $expr filters - #2864
Natansal-weme wants to merge 1 commit into
Conversation
Relation filters select the related model under a generated alias, so a `$expr` that qualifies references with the model name fails with a missing FROM-clause entry. `$expr` now receives a context with `modelAlias`, typed as the model name like the expression builder scope. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 🧰 Additional context used📚 Code guidelines (1)No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: zenstackhq/zenstack/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthrough
Changes$expr model alias context
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Suggested reviewers: Merge Risk: ⚪ Minimal · up to The alias context enables qualified expressions in relation filters while retaining existing one-argument callbacks. No actionable merge-blocking issue was identified; the change is mergeable subject to normal checks. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change exposes the current query alias without adding database privileges. The inspected relation filters retain their correlation constraints. No introduced security issue was identified in these paths, but broader authorization coverage remains incomplete. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Some tools did not complete. Review the errors below. 🔧 ESLint
packages/orm/src/client/crud-types.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. packages/orm/src/client/crud/dialects/base-dialect.tsESLint skipped: the matched ESLint configuration already failed (missing-dependency). 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 |
Fixes #2863
Relation filters select the related model under a generated alias (e.g.
"User" as "$$_Post$author"), but$expronly receives the expression builder, so it can't qualify references to the filtered model. A qualified reference like'User.email'type-checks and then fails withmissing FROM-clause entry for table "User".$exprnow gets a secondcontextargument withmodelAlias, mirroring the context computed field implementations already receive:ExprFilterContext<Schema, Model>typesmodelAliasas the model name, matching the expression builder's scope, soeb.ref(`${modelAlias}.field`)type-checks without casts. At runtime it holds the real alias.(eb) => ...callbacks keep working, including unqualified references.Tests
tests/regression/test/issue-2863.test.ts: top-level, to-one and to-many relation filters usingmodelAlias, plus unqualified references in a relation filter. Passes on SQLite and PostgreSQL.tests/e2e/orm/client-api/find.test.ts: the same qualified references with a typed client, to cover the typing.tests/e2e/orm/client-apion SQLite: everything passes except the two MySQL timezone tests, which need a MySQL server I don't have locally.Summary by CodeRabbit
$exprfilters now provide the current model alias as a second callback argument, enabling qualified field references in top-level and relation filters.