-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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.5] Serialize relationships #21191
Conversation
- add new `getQueueableRelations` method to queuable interfaces - accept the 'relations' into the `ModelIdentifier` - implement `getQueueableRelations` method on Eloquent Collection and Model. - extract a method on `SerializesAndRestoresModelIdentifiers` for `restoreModel`. Load the relationships in this method. - add test
What is the goal for this? What's wrong with lazy loading relationships in the queue? |
When you are dealing with the models in PHP, it is fine. This problem arises when you are using a service like Pusher to interact with your models in your Vue/JS code. For example, when I pushed an |
I see. Nice |
Hi! This is not exactly the same thing but I've made a package to import and export a model and it's relationships from/to json. You can find it at https://github.com/mathieutu/laravel-json-syncer. Tell me if I can help with that! 😉 |
@browner12 since you're asking: yes, it's a BC break. Changing the method signature is a BC break, so if adding a new parameter to a constructor, it would need to target 5.6, or give the parameter a default. You can then make a second PR to master to remove the default parameter. |
Yeah, as it stands now we would have to target this to 5.6. I think it's worth of having so probably worth re-targeting. |
Can you re-submit to master branch? |
resubmitted to master in #21229. I'd still like to get it into 5.5 if possible. It might be a little ugly, but I think it's worth it. I think the following would be the necessary steps:
thoughts? |
Previous attempt: #20602
Currently when you serialize a model (usually to place on a queue), and then unserialize, the model is reloaded fine, but the relationships are not. My previous solution was to have the user define on the queued object which relationships to reload. Taylor wanted something more automatic, so this PR will examine the model while it is being serialized and add the currently loaded relationships to the
ModelIdentifier
. Then, when the object is unserialized, will automatically reload all of the previously loaded relationships.Some things to consider:
Collection
relationships in this PR. I want to make sure this works and is accepted first, and then go back to add. Should be straightforward since all of the pieces are already there.$relations
parameter of theModelIdentifier
constructor optional? If I don't, am I technically making a BC break on a minor release?Thanks!