【发布时间】:2013-01-11 04:57:10
【问题描述】:
我有三个对象:
类别、文章和图片。
Categories 和 Article 具有双向 OneToMany 关联。 文章和图片具有双向 OneToMany 关联。
如何获得某个类别及其所有文章以及每篇文章的所有图像?
最后我想得到:
categorie.articles[0].images[0].URL(树枝语法)
PS:URL是Image的参数。
通过创建自定义存储库函数,我成功地将相关文章归入某个类别:
public function getCategoryWithArticles($article)
{
$qb = $this->_em->createQueryBuilder();
$qb->select('a')
->from('SiteBundle:Category', 'a')
->where('a.article= :article')
->setParameter('article', $article);
$qb->leftJoin('a.articles', 'c')
->addSelect('c');
return $qb->getQuery()
->getResult();
}
What should I add to get also the Images associated to each article ?
【问题讨论】:
标签: php sql symfony doctrine-orm