Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order a DQL Join by count on assiociation

I have a DQL query likes this:

$dql = "SELECT p, count(u.id) as ucnt FROM IAA\Entity\Project p " .
       "JOIN p.likedByUsers u ORDER BY ucnt";
$query = $this->_em->createQuery($dql);

Question is, how can I hold on to sorting by count, but NOT get them in result? I want to get only projects sorted by count, not array with [project] and [ucnt].

like image 566
Bartosz Rychlicki Avatar asked Oct 08 '22 21:10

Bartosz Rychlicki


1 Answers

Starting from Doctrine 2.2 (source) :

SELECT a, COUNT(b.id) AS HIDDEN c [...] ORDER BY c
like image 139
Maël Nison Avatar answered Oct 19 '22 17:10

Maël Nison