crz4dq
Last Updated: February 25, 2016
·
3.722K
· andreia
Mesr

Defining a column to be the key of the result hydrated as array in Doctrine 2

It's really simple, just use "INDEX BY" and specify the column in your query:

$em = $this->getEntityManager();
$query = $em->createQuery('SELECT c FROM SomeBundle:Configuration c INDEX BY c.name');
$query->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);

Reference: http://docs.doctrine-project.org/en/latest/reference/dql-doctrine-query-language.html#using-index-by

Say Thanks
Respond