I have User
and UserGroup
entities. Each user has a group (UserGroup
), and each user has a boss (User
).
I would like to get a list of groups, and decide if the current user is the boss of someone in the group. I already implemented this in SQL, and now I tried to solve it using Doctrine. This is what I tried:
$qb = em()->createQueryBuilder()
->select(array('gr.id AS group_id', 'gr.name AS group_name', 'COUNT(us.boss = :current_user_id)>0 AS is_boss'))
->from('\App\Entity\UserGroup', 'ug')
->leftJoin('\App\Entity\User', 'us', 'WITH', 'us.group = ug.id')
->setParameter('current_user_id', $_SESSION['uid'])
->groupby('gr.id')
;
$groups = $qb->getQuery()->getScalarResult();
Unfortunately I get an uncaught QueryException
, and I have no idea how to fix that. How is it possible to put an expression inside the COUNT(...)
function?