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

Merged
merged 1 commit into from
Aug 1, 2018
Merged

[5.5] Fix $withCount binding problems #24865

merged 1 commit into from
Aug 1, 2018

Conversation

staudenmeir
Copy link
Contributor

@staudenmeir staudenmeir commented Jul 16, 2018

Backport of #24240 and b91ae1f.

Using $withCount with a relationship that has bindings breaks DELETE queries.

class Article extends Model {
    protected $withCount = ['comments'];

    public function comments() {
        return $this->morphMany(Comment::class, 'commentable');
    }
}

Article::find(1)->delete();
// expected: delete from "articles" where "id" = 1
// actual:   delete from "articles" where "id" = App\Article

This problem has been fixed on MySQL, but not on the other databases.
This PR fixes it on all databases and also fixes #23957 on 5.5.

Fixes #22413.

Can you release 5.5.41 with support for MySQL 8.0 (#24038)?

@taylorotwell taylorotwell merged commit cab365a into laravel:5.5 Aug 1, 2018
@staudenmeir staudenmeir deleted the withcount-bindings branch August 1, 2018 13:54
@alexweissman
Copy link

Is it possible to backport this to 5.4 as well? In my case, this seems to happen when I cause a polymorphic withCount clause to be removed by adding a select clause to my query later on.

The select clause removes the select...count...where... created by withCount from the query, but the bindings are still present. This causes the entire bindings array to be shifted so that they no longer match with their intended placeholders.

@staudenmeir
Copy link
Contributor Author

staudenmeir commented Aug 2, 2018

Unfortunately, 5.4 isn't supported any more.

Does this PR fix your problem? Then you can "backport" it to your application.

@mnabialek
Copy link
Contributor

mnabialek commented Aug 2, 2018

@alexweissman This is known issue I believe (combining select and withCount with other order) - see #24797

@alexweissman
Copy link

@staudenmeir I'm using Eloquent as a standalone third-party package, so I'll have to create my own fork of 5.4 and merge this PR to test it. I'll give it a shot after my deadline.

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.

4 participants