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

[8.x] Load collection relations on serialisation restore #35720

Closed

Conversation

joshhanley
Copy link
Contributor

@joshhanley joshhanley commented Dec 26, 2020

This PR ensures collection relations are restored after an eloquent collection has been serialised.

This feature was introduced in PR #21191 for single models, and merged in PR #21229, with this feature to be added to collections in a later PR (as noted on the original PR). But I couldn't find any follow up PR that added this.

The use-case I have for this, is for Livewire.

Livewire uses this feature to serialise and restore model properties and eloquent collection properties. Currently model properties restore correctly, but eloquent collections do not, causing an n+1 problem when blade templates iterate through any relations. See this issue on Livewire repo as an example livewire/livewire#2010.

Hope this helps!

@taylorotwell
Copy link
Member

I am personally wary of changing this behavior on a patch release. We are having way too many accidental breaking changes lately.

@joshhanley
Copy link
Contributor Author

@taylorotwell yeah fair enough. Can I add any more tests that would make you comfortable merging this into 8.x or would you prefer I sent this to master?

@austenc
Copy link
Contributor

austenc commented Dec 29, 2020

Although it could be solved on the Livewire side, this seems like it'd be an improvement to the serialization features of the framework instead. Think I've run into this in the past when using queued jobs too. If you're dealing with a ton of relations it seems like it could slow things down, but that's the only potentially bad scenario that comes to mind.

Any other potential downsides you can think of?

@calebporzio
Copy link
Contributor

Just chiming in to echo what Josh and Austen have said.

I consider this expected behavior because Laravel already preserves single model relationships.

You would expect model collections to do the same.

We can solve this on the Livewire side, but would be a great upstream Laravel fix to have in core so people could benefit when dealing with Queues.

@driesvints
Copy link
Member

I think a new PR to master can be reconsidered maybe. Seems like Taylor just doesn't wants to do this on the current stable release.

@bilfeldt
Copy link
Contributor

@driesvints is this worth reconsidering as something worth including in th upcoming Laravel 9? 🤞 Of cause that deadline is approaching fast 😄

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.

6 participants