Symfony doctrine存储库按顺序排序

时间:2016-11-07 13:38:15

标签: php symfony doctrine repository

我有几张桌子,并为它获得了结果。

$qb = $this->createQueryBuilder('a');
$qb->select("a, c, ac")
   ->leftJoin('a.categories', 'c')
   ->leftJoin('a.comments', 'ac')
   ->where('c.slug = :category')
   ->setParameter('category', $category)
   ->orderBy('a.name', 'ASC');
return $qb->getQuery();

我想要这个结果,按评论(ac)计数。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

$qb = $this->createQueryBuilder('a');
$qb->select("a, c, ac, count(a.comments) AS HIDDEN nbcomments")
   ->leftJoin('a.categories', 'c')
   ->leftJoin('a.comments', 'ac')
   ->where('c.slug = :category')
   ->setParameter('category', $category)
   ->orderBy('a.name', 'ASC')
   ->addOrderBy('nbcomments', 'ASC');
return $qb->getQuery();