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
Written by Andréia Bohner
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Array
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#