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

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

merged 1 commit into from Mar 13, 2020


Copy link

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
7 checks passed
7 checks passed
P7.2 - Sprefer-lowest
P7.2 - Sprefer-stable
P7.3 - Sprefer-lowest
P7.3 - Sprefer-stable
P7.4 - Sprefer-lowest
P7.4 - Sprefer-stable
continuous-integration/styleci/pr The analysis has passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.