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

[5.1] Fix wrong PDO bindings when using whereHas() #15723

Merged
merged 2 commits into from
Oct 3, 2016

Conversation

marcotisi
Copy link
Contributor

Hi guys,

this PR will fix a bug with Eloquent Builder when querying a scoped Model using whereHas().
I create a test which fully explain the situation.

Basically when merging wheres to the $hasQuery, the bindings should not be the complete query bindings (which includes join also) but only where bindings.

I think that this should resolve #11261, #9696, #9628

Before:

$hasQuery->mergeWheres(
    $relationQuery->wheres, $relationQuery->getBindings()
);

After:

$whereBindings = array_get($relationQuery->getRawBindings(), 'where', []);
$hasQuery->mergeWheres($relationQuery->wheres, $whereBindings);

@taylorotwell
Copy link
Member

@acasar is this correct?

@acasar
Copy link
Contributor

acasar commented Oct 3, 2016

@taylorotwell Looks good 👍

I was thinking we could add an optional $type parameter to getBindings() so we could do:

$relationQuery->getBindings('where')

instead of:

array_get($relationQuery->getRawBindings(), 'where', [])

But this might be a breaking change?

Also, this won't merge into 5.3 easily. It may be easier to just transfer the code manually.

@marcotisi
Copy link
Contributor Author

I think that this bug is also present in branches 5.2 and 5.3, but unfortunately debugging this was a big deal, and I think I don't have the time to do also for 5.2 and 5.3 branches.

@taylorotwell taylorotwell merged commit 44a9fcf into laravel:5.1 Oct 3, 2016
@taylorotwell
Copy link
Member

@acasar would it be hard to send a PR for this to the 5.3 branch?

@marcotisi marcotisi deleted the 5.1 branch October 3, 2016 14:30
@marcotisi marcotisi restored the 5.1 branch October 3, 2016 14:31
@acasar
Copy link
Contributor

acasar commented Oct 3, 2016

@taylorotwell Shouldn't be that hard. I'll prepare a PR later today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants