问题
Is there a simple way to recursively hydrate all related objects when performing a query?
Let's say I have the following tables:
Song
Composer
Century
When I do a SongPeer::doSelectJoinAll()
only the related composers are hydrated, so if I then do something like $song->getComposer()->getCentury()
, a new query will be performed.
I want to perform only one query to the DB so when I call $song->getComposer()->getCentury()
within a loop on all my songs objects, it doesn't end up in n additional queries.
Hope I'm clear :)
Thanks
回答1:
Are you using Propel 1.2 ? The one with creole ?
If so, try to implement your own doSelectJoinAll
on SongPeer to manually add join on other table (like century).
If you are using the latest version, you just have to explicit joinWith the table in your query:
<?php
$song = SongQuery::create()
->joinWith('Song.Composer')
->joinWith('Composer.Century');
$century = $song->getComposer()->getCentury();
来源:https://stackoverflow.com/questions/10110033/recursively-hydrate-all-related-objects-in-propel