fix(orm): resolve delegate-inherited fields in cursor pagination#2591
fix(orm): resolve delegate-inherited fields in cursor pagination#2591ymc9 merged 2 commits intozenstackhq:devfrom
Conversation
…stackhq#2588) buildCursorFilter hardcoded the child model alias for both the outer reference and the sub-select projection, so `cursor` combined with `orderBy` on a @@DeleGate parent field produced a "column does not exist" error. Mirror the originModel-aware resolution already used by buildFilter and buildOrderBy.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughCursor pagination now resolves fields inherited via @@DeleGate by using the origin model's aliases for outer comparisons and inner subqueries; a regression test validates cursor + orderBy scenarios involving delegated parent fields. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 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 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/regression/test/issue-2588.test.ts`:
- Around line 21-26: The test currently uses very short 2ms sleeps between
db.notification.create calls which can cause flaky createdAt ordering; update
the test in issue-2588.test.ts to either set explicit createdAt timestamps on
the created notifications (pass createdAt in the data for the calls to
db.notification.create for a deterministic order) or increase the inter-create
delay to a safer value (e.g., 10–20ms) before creating b and c to ensure stable
ordering in CI.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 84f28bdf-906e-410f-b5e0-45fb6189d77d
📒 Files selected for processing (2)
packages/orm/src/client/crud/dialects/base-dialect.tstests/regression/test/issue-2588.test.ts
Sleep-based ordering is flaky on SQLite (1ms now() resolution) under CI scheduling jitter. Use deterministic createdAt values instead.
Summary
Closes #2588.
buildCursorFilterhardcoded the child model alias for both the outer reference and the sub-select projection, sofindMany({ cursor, orderBy: { <delegate-parent-field>: ... } })errored withcolumn "Child.field" does not exist. The fix mirrors theoriginModel-aware field resolution already used bybuildFilterandbuildOrderBy— when a field hasoriginModel, reference the parent table alias (whichbuildSelectModelalready joins using the parent's model name).Test plan
tests/regression/test/issue-2588.test.tscovering delegate-parent cursor, cursor+skip, mixed child/delegate orderBy, and child-only baseline.tests/e2e/orm/client-api/find.test.tspass (18/18).Summary by CodeRabbit
Bug Fixes
Tests