【发布时间】:2010-12-16 11:13:37
【问题描述】:
假设我们有两个模型:Post 和 ViewsCount。关系类型为 1:1。
现在我想检索最近 5 个帖子及其观看次数统计信息:
$posts = PostTable::getInstance()->createQuery('p')
->leftJoin('p.ViewsCount') // relation name is "ViewsCount"
->orderBy('p.created_at DESC')
->limit(5)
->execute();
但是,没有运气。它抛出一个错误。如果我取消加入 - 一切正常。
所以,我的问题是 - 如何在 Doctrine 中自动加入/检索一对一关系以避免大量额外查询?
【问题讨论】:
标签: orm symfony1 doctrine entity-relationship