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

[12.x] Fix pivot model events not working when using the withPivotValue #55280

Open
wants to merge 1 commit into
base: 12.x
Choose a base branch
from

Conversation

amir9480
Copy link
Contributor

@amir9480 amir9480 commented Apr 5, 2025

Fixes #55026.

  • For updateExistingPivot, there is no extra cost in terms of performance; it's already sending a database query for fetching data when using the updateExistingPivot method for custom classes. (InteractsWithPivotTable.php#L242)
  • For detach, a query like updateExistingPivot will be run before deleting, only if the user uses a custom pivot class and withPivotValue (or wherePivot), otherwise, it's working exactly as it was working before.
  • The previous version of updateExistingPivot used the collection where method instead of query builder where method, so I added a new method to get currently attached pivot models with related keys filter, so the where method will run by query builder instead of collection for better performance and not fetching data that is not needed for update/delete pivots.

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.

Adding pivot values causes the pivot model observer not work properly
1 participant