Uh oh!
There was an error while loading. Please reload this page.
fix(orm): to-one relation filter missing delegate base join - #2771
Conversation
Filtering a to-one relation whose target is a polymorphic subtype by a field inherited from the delegate base failed with `missing FROM-clause entry for table "<Base>"` (Postgres) / `no such column: <Base>.<field>` (SQLite). `buildToOneRelationFilter` built its `exists` subquery with a bare `selectFrom` on the concrete model, so the delegate base tables were never joined. `buildFilter` references base-inherited fields through `fieldDef.originModel`, i.e. qualified with the base model name, so the generated SQL named a table absent from the FROM clause. Use `buildSelectModel` - the same helper `buildToManyRelationFilter` already uses, which joins all delegate bases. That's why `some`/`none` filters worked while the to-one form didn't. Fixes#2768 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe to-one relation filter subquery now uses ChangesDelegated relation filters
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
Uh oh!
There was an error while loading. Please reload this page.
Fixes#2768
Problem
Filtering a to-one relation whose target is a polymorphic subtype, by a field inherited from the delegate base, failed at the database:
The generated SQL referenced the base table without joining it:
Cause
BaseCrudDialect.buildToOneRelationFilterbuilt itsexistssubquery with a bareselectFromon the concrete model, so delegate base tables were never joined.buildFilterreferences base-inherited fields throughfieldDef.originModel— qualified with the base model name — hence the dangling reference.buildToManyRelationFilteralready usedbuildSelectModel, which joins all delegate bases. That asymmetry is whysome/nonefilters worked while the to-one form didn't.Fix
Use
buildSelectModelin the to-one path as well.Verification
tests/regression/test/issue-2768.test.ts— 4 cases. The three to-one cases (base FK field, base scalar withstartsWith, base relation) each failed before this change; the to-many case is included to lock in the path that already worked.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
someandnoneconditions.Tests