spotorm / spot2

Spot v2.x DataMapper built on top of Doctrine's Database Abstraction Layer
http://phpdatamapper.com
BSD 3-Clause "New" or "Revised" License
601 stars 101 forks source link

Eager Loading #166

Open adamdyson opened 8 years ago

adamdyson commented 8 years ago

I'm evaluating various PHP ORM's that allow nested relationships to be eager loaded. Does this library have similar functionality to Propel, CakePHP, Eloquent etc?

$books = App\Book::with('author.contacts')->get();
nebulousGirl commented 8 years ago

Yes it has:

$bookMapper = $spot->mapper('BookEntity');
$books = $bookMapper->all()->with('author');

See the docs: http://phpdatamapper.com/docs/relations/#Eager_Loading

adamdyson commented 8 years ago

@nebulousGirl Thanks for the reply, however I'm asking whether nested relationships can be eager loaded. The example you posted and the documentation simply shows how to load a direct relationship. Ideally I'm wanting to achieve:

$bookMapper = $spot->mapper('BookEntity');
$books = $bookMapper->all()->with(['author.contacts', 'publisher']);
vlucas commented 8 years ago

Nested relationship eager loading is not currently supported, but it certainly would be nice.

adamdyson commented 8 years ago

I'm curious what the chances are of this ever being implemented?

nebulousGirl commented 8 years ago

I would really like to see this implemented as well. We just need someone with the time to tackle it. Unfortunately, I can't do it at the moment. I might have some time in the next few months.