Could not find a reliable solution for this, but I have a mySQL query that I want to translate into Doctrine. This is a selection from a subquery with joins, and I may have read somewhere that joins are not allowed in subqueries in the Doctrine.
Here is the SQL:
SELECT part, SUM(qty) as qty FROM (SELECT part, SUM(qty) as qty FROM sub LEFT JOIN main ON main.id = main_id WHERE hold != 1 GROUP BY name, part) AS tbl GROUP BY part
This is what I tried, and all this is wrong.
$em = $this->getDoctrine()->getManager();
$q = $em->createQuery('v');
$q2 = $em->createSubQuery()
->select('m.part, sum(s.qty) qty')
->from('Sub s')
->leftJoin('s.main m')
->where('s.hold != 1')
->groupBy('m.part');
$q->select('m.part, sum(qty)', $q2->getDQL());
One of the first errors I received was:
FatalErrorException: Error: Call to undefined method Doctrine\ORM\EntityManager::createSubQuery() in ....Controller.php line 238
I am sure that this is not just what I am doing wrong, but this is the first thing that fits. So getManager()apparently doesn't have a function createSubQuery()? What is the right way to do this?
source
share