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.8] Fix BelongsToMany::detach() with custom pivot class #27997

Merged
merged 1 commit into from
Mar 25, 2019
Merged

[5.8] Fix BelongsToMany::detach() with custom pivot class #27997

merged 1 commit into from
Mar 25, 2019

Conversation

staudenmeir
Copy link
Contributor

#27571 broke detach() and updateExistingPivot() when the relationship uses a custom pivot class in combination with wherePivot()/wherePivotIn():

class User extends Model
{
    public function roles()
    {
        return $this->belongsToMany(Role::class)
            ->using(RoleUserPivot::class)
            ->wherePivot('active', true);
    }
}

$user->roles()->detach(1);

// expected
delete from `role_user` where `active` = 1 and `user_id` = 1 and `role_id` in (1)

// actual
delete from `role_user` where (`user_id` = 1 and `role_id` = 1)

cadea88 fixed updateExistingPivot(), this PR fixes detach() the same way.

@TBlindaruk
Copy link
Contributor

@staudenmeir
I have created issue for tests #28025

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.

3 participants