Created
June 25, 2014 20:00
-
-
Save zrod/5ec50388e4c5bdc71194 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$resultSetMapping = new ResultSetMapping(); | |
$resultSetMapping->addEntityResult('MyAppBundle:Phone', 'p'); | |
$resultSetMapping->addFieldResult('p', 'id', 'id'); | |
$resultSetMapping->addFieldResult('p', 'master_id', 'masterId'); | |
$resultSetMapping->addFieldResult('p', 'slug', 'slug'); | |
$resultSetMapping->addFieldResult('p', 'price', 'price'); | |
$resultSetMapping->addFieldResult('p', 'name', 'name'); | |
$query = $this->getEntityManager()->createNativeQuery(' | |
SELECT * FROM | |
( | |
SELECT * FROM Phone | |
ORDER BY price ASC | |
) AS Phones | |
GROUP BY Phones.master_id | |
ORDER BY Phones.displayOrder | |
', $resultSetMapping); | |
return $query->getResult(); | |
/* Is there a better way to achieve that with doctrine? Here's the plain sql query: */ | |
SELECT * FROM (SELECT * FROM Phone ORDER BY price ASC) AS Phones GROUP BY Phones.master_id ORDER BY Phones.displayOrder; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment