0
我有Album,Content,File和Comment实体,其中Comment和File是Content的关系,Content与Album相关。优化Doctrine 2实体关系加载
我想从单个内容实体中检索所有关系(文件和评论实体)(并且不加载任何其他内容)。数据库应该不超过2个查询。
什么是使用单个查询检索关系并填充实体对象的好方法?
E.G
$album = $em->createQuery('SELECT a,c FROM Album JOIN a.contents c WHERE a.id = :id')->getOneOrNullResult();
foreach ($album->getContents() as $content) {
if ($content->getId() == $id) {
// Load all (relevant) relations for this content in a single query with joins
$em->MAGIC($content);
}
}