Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent
Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

@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.

Last updated 2 years ago.
0

what about something like this ?

$a = A::with('b1.c', 'b2.c')->get();
Last updated 2 years ago.
0

@jawb it looks like your code is not available anymore, can you post it again?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

jawb jawb Joined 16 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.