Hello I want to create a complex query where I need request info from 5 tables and group it by companies.name applying a filter by branches.idMunicipality my query is the next:
$em = $this->getDoctrine()->getManager();
$companies = $em->createQuery('
SELECT categories,
subcategories,
companies,
branches,
sales
FROM AspersoftDirectorioBundle:CompanyCategory categories
JOIN categories.subcategories subcategories
JOIN subcategories.companies companies
JOIN companies.branches branches
LEFT JOIN companies.sales sales
WHERE branches.idMunicipality = :idMunicipality
GROUP BY companies.id
ORDER BY categories.name ASC'
)
->setParameter('idMunicipality' , "475")
->getResult();
return $companies;
My issues are:
- My DB is bidirectional in all tables then I have 27 DB querys (page loads very low)
- Group by don't work
- In my opinion is very hard get values in views because I need to use 4 or 5 "for"
Thank in advance for your help