Skip to content

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

Merged
taylorotwell merged 1 commit into
laravel:5.8from
staudenmeir:detach
Mar 25, 2019
Merged

[5.8] Fix BelongsToMany::detach() with custom pivot class#27997
taylorotwell merged 1 commit into
laravel:5.8from
staudenmeir:detach

Conversation

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