Recursively hydrate all related objects in Propel

拥有回忆 提交于 2019-12-11 05:29:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!