我有几张桌子,并为它获得了结果。
$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)计数。我该如何解决这个问题?
答案 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();