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.6] Fix BelongsToMany pivot relation wakeup #23081

Merged
merged 1 commit into from
Feb 8, 2018
Merged

[5.6] Fix BelongsToMany pivot relation wakeup #23081

merged 1 commit into from
Feb 8, 2018

Conversation

rodrigopedra
Copy link
Contributor

As described in issue #23068 when a model with a BelongsToMany relation is unserialized, the pivot relation fails to reload as it does not have an explicit relation method in the Model.

This PR tries to fix this issue by verifying if an explicit relation method exists before serializing that relation.

Some tests were changed to reflect this updates.

P.S.: I am not sure if this is the best approach, and if calling getQueueableRelations from the first model in a collection could lead to a circular reference problem when serializing.

But as this issue is preventing me to migrate to Laravel 5.6 I tried to fix it in the most reasonable way. Any further help is appreciated.

@rodrigopedra rodrigopedra changed the title fix BleongsToMany pivot relation wakeup fix BelongsToMany pivot relation wakeup Feb 8, 2018
foreach ($relation->getQueueableRelations() as $collectionKey => $collectionValue) {
$relations[] = $key.'.'.$collectionKey;
foreach ($relation->getQueueableRelations() as $collectionValue) {
$relations[] = $key.'.'.$collectionValue;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this change a bit more? Why did you make this change?

Copy link
Contributor Author

@rodrigopedra rodrigopedra Feb 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in the Collection I am returning the result of getQueueableRelations instead of the previous getRelations it returns an integer-indexed array with the name of the relations from the first model in the collection., so I used the values instead of the keys.

@taylorotwell taylorotwell merged commit 0c9beda into laravel:5.6 Feb 8, 2018
@taylorotwell
Copy link
Member

Tagged 5.6.1. Thanks.

@GrahamCampbell GrahamCampbell changed the title fix BelongsToMany pivot relation wakeup [5.6] Fix BelongsToMany pivot relation wakeup Feb 10, 2018
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.

None yet

2 participants