在 Propel 中递归地水合所有相关对象 [英] Recursively hydrate all related objects in Propel

查看:42
本文介绍了在 Propel 中递归地水合所有相关对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以在执行查询时递归地对所有相关对象进行水合?

Is there a simple way to recursively hydrate all related objects when performing a query?

假设我有以下表格:

Song
Composer
Century

当我执行 SongPeer::doSelectJoinAll() 时,只有相关的作曲家是水合的,所以如果我再做类似 $song->getComposer()->getCentury(),将执行一个新的查询.

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.

我只想对数据库执行一个查询,因此当我在所有歌曲对象的循环中调用 $song->getComposer()->getCentury() 时,它不会t 最终会出现 n 个额外的查询.

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.

希望我很清楚:)

谢谢

推荐答案

你在使用 Propel 1.2 吗?那个带有克里奥尔语的?

Are you using Propel 1.2 ? The one with creole ?

如果是这样,请尝试在 SongPeer 上实现您自己的 doSelectJoinAll 以手动在其他表(如 Century)上添加连接.

If so, try to implement your own doSelectJoinAll on SongPeer to manually add join on other table (like century).

如果您使用的是最新版本,您只需明确的joinWith 在您的查询中:

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();

这篇关于在 Propel 中递归地水合所有相关对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆