Skip to content

Add wrapWhere option to QueryScope#568

Merged
roxblnfk merged 1 commit into
2.xfrom
query-scope-wrap-where
Jun 2, 2026
Merged

Add wrapWhere option to QueryScope#568
roxblnfk merged 1 commit into
2.xfrom
query-scope-wrap-where

Conversation

@roxblnfk

@roxblnfk roxblnfk commented Jun 2, 2026

Copy link
Copy Markdown
Member

🔍 What was changed

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

`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

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.61%. Comparing base (cd4ea0f) to head (e116df0).
⚠️ Report is 1 commits behind head on 2.x.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@roxblnfk roxblnfk merged commit 9f35880 into 2.x Jun 2, 2026
31 of 35 checks passed
@roxblnfk roxblnfk deleted the query-scope-wrap-where branch June 2, 2026 09:48
@roxblnfk roxblnfk added the type:feature New feature. label Jun 2, 2026
@roxblnfk roxblnfk added this to Cycle Jun 2, 2026
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Cycle Jun 2, 2026
@github-project-automation github-project-automation Bot moved this to In Progress in Cycle Jun 2, 2026
@roxblnfk roxblnfk added this to the 2.17.x milestone Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:feature New feature.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant