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

[5.8] fix many to many sync results with custom pivot model #28416

merged 6 commits into from May 5, 2019


None yet
3 participants
Copy link

commented May 5, 2019

This PR fixes an issue (#28150) where the results of sync() while updating "Custom Pivot Model" attributes always show the record as updated even if it's not.

The reason was that we weren't loading the actual pivot model from the database and thus we didn't have any way to compare the newly provided data with the existing one.

My solution here is that we load the model from the database first, and use isDirty() to check if the attributes were update or not.

themsaid added some commits May 5, 2019

@taylorotwell taylorotwell merged commit 35f6cc8 into laravel:5.8 May 5, 2019

2 checks passed

continuous-integration/styleci/pr The analysis has passed
continuous-integration/travis-ci/pr The Travis CI build passed

This comment has been minimized.

Copy link

commented May 9, 2019

Hey @themsaid, I think this PR caused a breaking change for me when trying to use updateExistingPivot when there were no records found:

Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function fill() on null
  File "/var/www/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php", line 227

My code snippet:
$ticket->subscribers()->updateExistingPivot(Auth::id(), ['last_read_at' => Carbon::now()]);

Did I use it wrong or is it broken when no records are found?


This comment has been minimized.

Copy link
Member Author

commented May 9, 2019

@pdewit if there are no records found then it's not an existing pivot, not sure why you're using updateExistingPivot then.

@themsaid themsaid deleted the themsaid:pr/2296 branch May 9, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.