-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Description
Laravel Version
12.20.0
PHP Version
8.3.21
Database Driver & Version
No response
Description
Bug description:
When using pivot tables with a pivot model, when using updateExistingPivot
, it updates all pivots with the related and foreign id's, even if other filters on pivot table columns are applied.
I haven't had the time to figure everything out, but it seems it has to do something with the changes in the following line:
Work-around:
Make sure pivot tables where an identical foreign and related combination is possible since another pivot table column is added to the primary key, are updated so they have a primary auto-incrementing key, this fixes the problem since the AsPivot::setKeysForSaveQuery
then uses the primary key instead of the foreignKey / relatedKey combination.
Related:
Steps To Reproduce
Since the code-base this is happening is closed, I cannot share the exact table's.
But an easy reproducible situation:
- create a
role
table - create a
team
table - create a
user_has_roles
table- This has two extra pivot columns:
team_id
andlast_used
(timestamp)
- This has two extra pivot columns:
Create a simple controller that makes it possible to switch between teams, where an user can have the same role_id for multiple teams in the pivot table.
I am happy to provide a working example later today, let me know if desired.