Skip to content

[5.6] Fix $withCount binding problems - #24240

Merged
taylorotwell merged 1 commit into
laravel:5.6from
staudenmeir:uneager-query
May 21, 2018
Merged

taylorotwell merged 1 commit into
laravel:5.6from
staudenmeir:uneager-query

Conversation

@staudenmeir

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Member

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

@staudenmeir

Copy link
Copy Markdown
Contributor Author

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');
});

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.

2 participants