Add wrapWhere option to QueryScope#568
Merged
Merged
Conversation
`QueryScope` adds its conditions at the top level of the query, where a user-supplied `orWhere` can bypass the scope due to AND-over-OR precedence (e.g. a `status = active` scope leaks on `where(id,1)->orWhere(id,2)`). Add a `wrapWhere` constructor flag that calls `QueryBuilder::wrapWhere()` before applying the scope conditions, enclosing already-registered user conditions in a parenthesized AND-group. For scopes on joined loaders the call is forwarded to the JOIN ON tokens via `wrapOnWhere`. The flag defaults to false to preserve backwards-compatible behavior. - QueryScope: new `wrapWhere` parameter with a thorough docblock - Unit tests for QueryScope apply/wrap behavior, including the empty-where edge case - HasMany integration tests switched from the throwaway WrappedQueryScope fixture to `QueryScope(wrapWhere: true)`, exercising the real class; the fixture is removed Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 2.x #568 +/- ##
=========================================
Coverage 91.60% 91.61%
- Complexity 2016 2017 +1
=========================================
Files 131 131
Lines 5232 5234 +2
=========================================
+ Hits 4793 4795 +2
Misses 439 439 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔍 What was changed
QueryScopeadds its conditions at the top level of the query, where a user-suppliedorWherecan bypass the scope due to AND-over-OR precedence (e.g. astatus = activescope leaks onwhere(id,1)->orWhere(id,2)).Add a
wrapWhereconstructor flag that callsQueryBuilder::wrapWhere()before applying the scope conditions, enclosing already-registered user conditions in a parenthesized AND-group. For scopes on joined loaders the call is forwarded to the JOIN ON tokens viawrapOnWhere. The flag defaults to false to preserve backwards-compatible behavior.wrapWhereparameter with a thorough docblockQueryScope(wrapWhere: true), exercising the real class; the fixture is removed