Skip to content

[12.x] Fix many to many detach without IDs broken with custom pivot class #55490

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

Merged
merged 1 commit into from
Apr 21, 2025

Conversation

amir9480
Copy link
Contributor

@amir9480 amir9480 commented Apr 20, 2025

Fixes #55428

This update causes an extra query for detaching without IDs when using a custom pivot class, but it has one benefit.
You may need pivot class data when deleting pivots. The previous implementation was like this:

foreach ($this->parseIds($ids) as $id) {
    $results += $this->newPivot([
        $this->foreignPivotKey => $this->parent->{$this->parentKey},
        $this->relatedPivotKey => $id,
     ], true)->delete();
}

The above code only provides the related pivot key and foreign pivot key for listeners that may be problematic in some scenarios when using pivot data in the listeners, but in the new implementation, we also have other pivot data in the listeners.

Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@amir9480 amir9480 marked this pull request as ready for review April 20, 2025 16:31
@taylorotwell taylorotwell merged commit 3073c3a into laravel:12.x Apr 21, 2025
60 checks passed
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.

ManyToMany relation detach without ids broken after 12.9.0 upgrade
2 participants