Repository navigation
[5.6] Ignore non-where bindings in nested where() constraints - #24000
Merged
Merged
Conversation
Member
|
Is it possible the nested where could legitimately have other bindings though? |
Contributor
Author
|
I tried to find a case, but couldn't think of one. We could also solve this problem at the root with something like This method would create a query without |
Contributor
|
I wrote a trait patch for this issue until this PR merged. https://gist.github.com/mpyw/cb43c4cbd48d1ae1f63df949b1cc896b |
Member
|
I kinda prefer the newQueryWithoutScopesWithoutCount approach if you have any better names ideas. Would be curious to see what that looks like. |
leoleoasd
pushed a commit
to leoleoasd/framework
that referenced
this pull request
May 21, 2018
Closed
salmanarshad321
pushed a commit
to salmanarshad321/framework
that referenced
this pull request
Sep 23, 2026
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.
Nested
where()constraints merge all bindings from the given query, even the ones from other query parts.This breaks queries that reference a relationship with
WHEREbindings (e.g.MorphMany) in$withCountand use a nestedwhere()constraint:The query doesn't work as expected because an extra binding is added:
As a result
'App\ParentModel'is used for the second placeholder and1is ignored.This is caused by
Model::newQueryWithoutScopes()adding$withCountto every query.So the query received by
Builder::where()contains the$withCountbindings.This PR solves the problem by ignoring non-where bindings when the nested query is merged.
Fixes #23957.