I have 2 entities linked by a one to many relation. Recruitment and Candidat You may have many candidats for one recruitment.
I want to list all recruitment and count how many candidat each recruitment has.
I use the recruitment repository and put the code:
public function myFindAllRecruitment() { $qb = $this->createQueryBuilder('r'); $qb->select('r'); $qb->Join('r.candidat', 'c'); $qb->addSelect("COUNT(c.id) as candidatCount"); $qb->groupBy('r.id'); $qb->orderBy('r.id', 'DESC'); return $qb ->getQuery() ->getResult() ; } In my RecruitmentController I have:
$listRecruitment = $repository->myFindAllRecruitment(); In my TWIG view something like:
{% for recruitment in listRecruitment %} <tr> {#(this is line 48)#}<td>{{ recruitment.id }}</td> <td>{{ recruitment.titleFr }}</td> <td>{{ recruitment.locationFr }}</td>...... And I get this error: "Key "id" for array with keys "0, candidatCount" does not exist in MyBundle:Recruitment:index.html.twig at line 48"
If someone knows what wrong with my query it will be nice. Thank you