Hi,
i searched quit some time and tried to figure out how to build this native
MySQL Query in Doctrine 2:
SELECT *
FROM `turn`
LEFT JOIN (
poi) ON ( turn.id = poi.turn_id )
GROUP BY turn.id
ORDER BY count( case when poi.image = 1 then 1 else null end) DESC;
I'm using Doctrine 2 within Symfony2 and tried to create it with the
QueryBuilder
$qb = $this->createQueryBuilder('t')
->select('t')
->join('t.pois', 'p')
->groupBy('t.id')
->addOrderBy('count((case when p.image = 1 then 1 else null end))', 'DESC');
But this attempt leads to this QueryExeption:
Twig_Error_Runtime: An exception has been thrown during the rendering of a
template ("[Syntax Error] line 0, col 115: Error: Expected end of string, got
'('") in Bundle:Admin:showTurnsFiltered.html.twig at line 64.
QueryException: [Syntax Error] line 0, col 115: Error: Expected end of string,
got '('
I also tried to build a DQL Query
$dql = "SELECT t FROM Mysailinglog\Bundle\MysailinglogBundle\Entity\Turn t
JOIN Mysailinglog\Bundle\MysailinglogBundle\Entity\Poi p GROUP BY t.id
ORDER BY count((CASE WHEN p.image = 1 THEN 1 ELSE 0 END)) DESC";
But the result is the same.
Can somebody help me?
I also asked this one on StackOverflow
<http://stackoverflow.com/questions/24527360/doctrine-2-order-by-count-with-join-for-symfony-2-pagerfanta>
if somebody wants to earn some Rep!
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.