fix(core): query-level order takes precedence over scope order in _injectScope#18214
fix(core): query-level order takes precedence over scope order in _injectScope#18214Aviel212 wants to merge 2 commits into
Conversation
…jectScope When a scoped model's findAll (or findOne/findByPk) is called with an explicit `order` option, the scope's `order` was being prepended to it due to the array union in _mergeFunction. This caused the scope order to always win, which is incorrect and a regression from Sequelize v3. Fix: if the query options already contain an `order`, delete the scope's `order` before merging so that the query-level order is the only one used. Closes sequelize#11415
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughUpdated Model._injectScope(options) so that when caller-provided Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 OpenGrep (1.17.0)packages/core/src/model.js┌──────────────┐ �[32m✔�[39m �[1mOpengrep OSS�[0m �[1m Loading rules from local config...�[0m 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 |
What
Fixes incorrect ordering when calling
findAll(orfindOne/findByPk) on a scoped model that has a predefinedorder.Why
When a scoped model's
orderwas merged into the query options via_injectScope, the internal_mergeFunctionusedunion(scope.order, query.order)for all arrays — causing the scope's order to always be prepended ahead of the query-level order. This is a regression from Sequelize v3 behavior where the explicit query order took full precedence.How
In
_injectScope, ifoptions.orderis already set by the caller, we deletescope.orderfrom the cloned scope before merging. The scope's order is still applied as a default when the query has no explicitorder.Tests
Added two unit tests to
test/unit/model/scope.test.ts:All 55 existing scope unit tests continue to pass.
Closes #11415
Summary by CodeRabbit
Bug Fixes
Tests