Skip to content

Instantly share code, notes, and snippets.

@zrod
Created June 25, 2014 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zrod/5ec50388e4c5bdc71194 to your computer and use it in GitHub Desktop.
Save zrod/5ec50388e4c5bdc71194 to your computer and use it in GitHub Desktop.
<?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