我正在编写一个类似于论坛的小型应用程序(在 Symfony2 中),我遇到了以下问题:
我有两个实体:
class ForumThread {
public $fourmThreadId;
public $title;
public $posts; // aggregation field -> ArrayCollection of ForumPost (can't be empty)
}
class ForumPost {
public $content;
public $timeCreated;
public $thread; // aggregation field -> ForumThread (can't be null)
}
我现在想获取所有论坛主题,包括每个主题的最新帖子。我想将它用于论坛概述:
-------------------------------------
| Thread | Last Post |
-------------------------------------
| Name of Thread #1 | ### |
| Name of Thread #2 | ### |
| ... | ... |
-------------------------------------
我想获取完整的ForumPost
实体,而不仅仅是单个字段(如时间戳)。
它也应该是高性能的:理想情况下在 1-2 个查询中(我在使用 INNER JOIN 的原始 SQL 中找到了一些东西,但我想要在 DQL 中或理想情况下使用 QueryBuilder - 我尝试从 SQL 到 DQL 的翻译没有成功)。