Skip to content

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

Merged
taylorotwell merged 5 commits into
laravel:9.xfrom
Propaganistas:bugfix-whereNot
Sep 12, 2022
Merged

[9.x] Fix QueryBuilder whereNot with array conditions #44083
taylorotwell merged 5 commits into
laravel:9.xfrom
Propaganistas:bugfix-whereNot

Conversation

@Propaganistas
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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