I wonder why you would want that ?
Anyway, you can't do any better with native Eloquent methods, but with a little bit of magic Laravel let you do that.
Imagine Category that has many posts (your b1) and has many _posts (your b2). You would like to load all posts for given Category in one query and set the relations accordingly.
Also you would like to be able to load the posts for a Collection of Categories.
So here's how to make it work: http://laravel.io/bin/q54O
There are 2 methods loadPosts() on the model and custom collection for this task.
Check this out and try to make the nested relation work alike.
@jarektkaczyk, Thank you that's what I did manually, but I better use $relation->match like you did, I think this optimization would be a good feature to have out of the box.
A synatx like this:
$a = A::all();
$a->load('b1:B', 'b2:B', 'b1.c:C', 'b2.c:C');
Or maybe just let Eloquent deduce Models from relation.
what about something like this ?
$a = A::with('b1.c', 'b2.c')->get();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community