You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After fixing #55026, there's a new issue when updating pivot tables with sync(). Conditions set by wherePivot() are no longer being applied, which results in more rows being updated than expected.
Steps To Reproduce
This is how I define my relationship:
public function texts(int $reportId):BelongsToMany{
return $this->belongsToMany(Text::class,'orders_texts','order_id','text_id')
->wherePivot('report_id',$reportId)
->using(OrderText::class)
->withPivot(
[
'report_id',
'included',
'content',
'status',
'comment'
]
)
->withTimestamps();
}
update "orders_texts" set "content" = ?, "updated_at" = ? where "order_id" = ? and "text_id" = ?"
This is missing the report_id condition which I set with wherePivot(), so all the rows in orders_texts with text_id=1 and order_id=5 (5 is the order ID) are being updated.
The query should include report_id, ie:
update "orders_texts" set "content" = ?, "updated_at" = ? where "report_id" = ? and "order_id" = ? and "text_id" = ?"
The text was updated successfully, but these errors were encountered:
As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.
If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.
Laravel Version
12.12.0
PHP Version
8.3.6
Database Driver & Version
No response
Description
After fixing #55026, there's a new issue when updating pivot tables with
sync()
. Conditions set bywherePivot()
are no longer being applied, which results in more rows being updated than expected.Steps To Reproduce
This is how I define my relationship:
I then run the following code:
The query actually being run is the following:
This is missing the
report_id
condition which I set withwherePivot()
, so all the rows inorders_texts
withtext_id=1
andorder_id=5
(5 is the order ID) are being updated.The query should include
report_id
, ie:The text was updated successfully, but these errors were encountered: