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
merged 1 commit into from May 21, 2018

Conversation

Projects
None yet
2 participants
@staudenmeir
Contributor

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)?

@taylorotwell

This comment has been minimized.

Member

taylorotwell commented May 18, 2018

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

@staudenmeir

This comment has been minimized.

Contributor

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
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@staudenmeir staudenmeir referenced this pull request May 22, 2018

Closed

[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