Doctrine 2: Query result as associative array

前端 未结 5 1427
傲寒
傲寒 2020-12-29 05:58

In my Repository class I use the following code to query:

$query = $this->getEntityManager()->createQuery(\"
    SELECT s.term, COUNT(s.term) AS freq
          


        
5条回答
  •  心在旅途
    2020-12-29 06:33

    Use INDEX BY :

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

    I saw it here and it works fine : https://coderwall.com/p/crz4dq/defining-a-column-to-be-the-key-of-the-result-hydrated-as-array-in-doctrine-2

提交回复
热议问题