Skip to content

[6.x] Unset pivotParent on Pivot::unsetRelations()#31956

Merged
taylorotwell merged 1 commit intolaravel:6.xfrom
23G:unset-pivot-relation
Mar 13, 2020
Merged

[6.x] Unset pivotParent on Pivot::unsetRelations()#31956
taylorotwell merged 1 commit intolaravel:6.xfrom
23G:unset-pivot-relation

Conversation

@axlon
Copy link
Contributor

@axlon axlon commented Mar 13, 2020

(Continuation of #31930)

Currently the Model::unsetRelations() method (and by extension the Model::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 unsetRelations or withoutRelations would solve this issue (in the case of a Model), but since Pivots have this extra relation it doesn't.

@taylorotwell taylorotwell merged commit 2b600ce into laravel:6.x Mar 13, 2020
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
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.

2 participants