title: Select one entity from doctrine query response array
body: <p>I am running the following query to fetch two entities from the database. </p>
  
  <pre><code>   return $this-&gt;createQueryBuilder('a')
          -&gt;select('a','u')
          -&gt;where('a.api_key = :api_key')
          -&gt;leftJoin(User::class, 'u', \Doctrine\ORM\Query\Expr\Join::WITH, 'a.user_id = u.id')
          -&gt;setParameter('api_key', $key)
          -&gt;getQuery()
          -&gt;getResult();
  </code></pre>
  
  <p>The query returns two entities as expected. However, the response is in the format of an indexed array. </p>
  
  <pre><code>array(2) {
      [0]=&gt; object(AppBundle\Entity\ApiKey)
      [1]=&gt; object(AppBundle\Entity\User)
  }
  </code></pre>
  
  <p>Do you know if there is a way in doctrine to get the response to be returned as an associative array, using the entity name as the index? Or is there a doctrine function that can select one entity from the query response? </p>
  
  <p>I only ask because I don't really like doing this: </p>
  
  <pre><code> $apiKey = null;
   $username = null;
   foreach ($result as $row) {
       if($row instanceof ApiKey::class){
           $apiKey = $row-&gt;getApikKey(); 
       }
       if($row instanceof User::class){
           $user = $row-&gt;getUsername();
       }
   }
  </code></pre>
  
  <p>And would prefer being able do to something like this: </p>
  
  <pre><code> $apiKey = $result [ApiKey::class]-&gt;getApiKey();
   $username = $result [User::class]-&gt;getUsername();
  </code></pre>