I am fetching associated objects through 3 tables (“User”,” Client”,” Account”). “User” has a one-to-many relationship to “Client”, “Client” has a one-to-many relationship to “Account”. I fetch all the “Accounts” for one specific “User” using the following code:
$qb = $this->getDoctrine()->getManager()->createQueryBuilder()
->select('u, c, a')
->from('AcmeUserBundle:User', 'u')
->leftJoin('u.clients', 'c')
->leftJoin('c.accounts', 'a')
->where('u.id = :id');
$user = $qb->getQuery()
->setParameter('id', $id)
->getOneOrNullResult();
I pass the $user array to a TWIG template but I can’t find the correct loop to retrieve all the accounts contained in the “$user” array. What is the best way to achieve this? What should be done in the Controller vs. what should be done in TWIG? Could you give me an example of code that would work? I looked at this answer but did not manage to apply the given guidance How to get values from a multidimensional array in Twig?