[6.x] Unset pivotParent on Pivot::unsetRelations() #31956
Merged
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
unsetRelations
orwithoutRelations
would solve this issue (in the case of a Model), but since Pivots have this extra relation it doesn't.