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

Merged
merged 1 commit into from
May 21, 2018
Merged

[5.6] Fix $withCount binding problems #24240

merged 1 commit into from
May 21, 2018

Conversation

staudenmeir
Copy link
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
Member

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

@staudenmeir
Copy link
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