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.6] Fix $withCount binding problems #24240

merged 1 commit into from May 21, 2018


None yet
2 participants

staudenmeir commented May 17, 2018

Model::newQueryWithoutScopes() adds $with and $withCount to every query.

This can cause problems if a $withCount relation has bindings (#23957, #22285, #21472, #21464, #21116).
It's also unnecessary for INSERT/UPDATE/DELETE queries.

This PR adds Model::newUneagerQueryWithoutScopes() which creates a query without $with & $withCount.
Should I add additional (integration) tests?

Since this is the better solution for #23957: Should we revert #24000 (in case a nested where can legitimately have other bindings)?


This comment has been minimized.


taylorotwell commented May 18, 2018

Is this only present when populating the $withCount property on the model directly?


This comment has been minimized.


staudenmeir commented May 18, 2018

I would say that it's only a problem when $withCount is populated. At least in case of the problem fixed by #24000 you can theoretically cause binding mismatches "manually", but that doesn't really make sense:

$query = ParentModel::where(function($q) {
    $q->where(1, 1)->withCount('children');

@taylorotwell taylorotwell merged commit 8c37b0d into laravel:5.6 May 21, 2018

2 checks passed

continuous-integration/styleci/pr The analysis has passed
continuous-integration/travis-ci/pr The Travis CI build passed

@staudenmeir staudenmeir referenced this pull request May 22, 2018


[5.6] Revert #24000 #24283

@staudenmeir staudenmeir deleted the staudenmeir:uneager-query branch May 25, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment