[6.x] Unset pivotParent on Pivot::unsetRelations()#31956
Merged
taylorotwell merged 1 commit intolaravel:6.xfrom Mar 13, 2020
23G:unset-pivot-relation
Merged
[6.x] Unset pivotParent on Pivot::unsetRelations()#31956taylorotwell merged 1 commit intolaravel:6.xfrom 23G:unset-pivot-relation
taylorotwell merged 1 commit intolaravel:6.xfrom
23G:unset-pivot-relation
Conversation
LukeTowers
added a commit
to wintercms/storm
that referenced
this pull request
Jan 24, 2022
Pivot::fromAttributes() instead of new Pivot(): laravel/framework@06f01cf & laravel/framework@4b30aad (protected) Pivot()->parent -> (public) Pivot()->pivotParent: laravel/framework@29a181f & laravel/framework@22c3c02 $otherKey -> $relatedKey: laravel/framework@d2a7777 Added fromRawAttributes() method to Pivot: laravel/framework@f356419 Various improvements to setKeysForSaveQuery(): laravel/framework@8d82618, laravel/framework@e9f37ed Fire model events when deleting Pivot models: laravel/framework#27571 Fixed Pivot serialization: laravel/framework@b52d314 & laravel/framework#31956
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(Continuation of #31930)
Currently the
Model::unsetRelations()method (and by extension theModel::withoutRelations()method) can be used to unset relations on Models, which is primarily useful right before serialization (e.g. queues)However the
pivotParent, which is a hardcoded relation on every Pivot instance, is not unset. This PR aims to fix that.For context, my particular use-case:
I have a queued job which accepts a Pivot as a constructor argument. If this Pivot has the pivotParent loaded PHP will crash as soon as Laravel starts to serialize the Pivot due to a circular reference between the Pivot and its parent causing an infinite loop.
Normally calling
unsetRelationsorwithoutRelationswould solve this issue (in the case of a Model), but since Pivots have this extra relation it doesn't.