Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Fix QueryBuilder whereNot with array conditions #44083

Merged
merged 5 commits into from
Sep 12, 2022
Merged

[9.x] Fix QueryBuilder whereNot with array conditions #44083

merged 5 commits into from
Sep 12, 2022

Conversation

Propaganistas
Copy link
Contributor

@Propaganistas Propaganistas commented Sep 10, 2022

$query->whereNot([
    'foo' => 1, 
    'bar' => 2
]);

currently yields not ( not foo = 1 and not bar = 2 )
while I would expect this to implictly become a nested clause not ( foo = 1 and bar = 2 ).

The commits in this PR are deliberately threefold:

  1. the actual bugfix + tests
  2. the consequence of reusing whereNested: aesthetically superfluous parentheses (but sql doesn't care).
  3. a missing variable interpolation I encountered on the go

Note: the PR only tackles Query\Builder. The same principle probably applies for Eloquent\Builder

@BrandonSurowiec
Copy link
Contributor

Since it has been like this for a long time this seems like a breaking change. Should probably target 10.x as someone out there is depending on the current behavior.

@rodrigopedra
Copy link
Contributor

whereNot was introduced earlier this year by PR #41096.

I agree with @Propaganistas the expected behavior when passing an array should not be to negate it twice.

@Propaganistas Propaganistas changed the title Fix whereNot with array conditions Fix QueryBuilder whereNot with array conditions Sep 11, 2022
@taylorotwell
Copy link
Member

Made the change only apply to arrays.

@taylorotwell taylorotwell merged commit 75ec9c3 into laravel:9.x Sep 12, 2022
@Propaganistas Propaganistas deleted the bugfix-whereNot branch September 13, 2022 15:33
@GrahamCampbell GrahamCampbell changed the title Fix QueryBuilder whereNot with array conditions [9.x] Fix QueryBuilder whereNot with array conditions Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants