-
Notifications
You must be signed in to change notification settings - Fork 101
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
Added the NestedRelation #290
base: master
Are you sure you want to change the base?
Conversation
Hey guys. Please tell me what do you think about this idea. I use it for one of my projects to avoid lazy-loading of related entities. This can save a lot of db queries. I would like to contribute it to Spot2. |
I like it! Somebody from the team will review it as soon as possible. |
Ok, great. Thanks. |
Hey guys, I added some tests to the new relation. Also I changed the way of adding nested relations to entities. So actually now there is no need to define them inside entities. Nested relations will be created automatically when added with 'with' method. So the only things to ensure is that all the parent levels are loaded and the target relation exists. For example: $posts->all()->with(['user_comments', 'user_comments.user']); For this case Post entity should have a 'user_comments' relation and UserComment entity should have 'user' relation. That will be enough for the above code to work. I can improve it further if there is a need. Thanks. |
NestedRelation can be used for eager-loading of multi-level related entities.
Usage example for Post Entity:
And then we can eager load user profiles with posts:
$posts = $posts->all()->with(['user', 'user.profile']);
NestedRelation can be used with any relations and can be multilevel. For example: