Use a column value of a Doctrine Entity as key of an array result

Code
<?php

use PHPSnippets\Db\Entity\Test;

// Index by uses a given value as result array key
// Be sure to use only primary or unique keys

// #### QueryBuilder ####

$repo $entityManager->getRepository(Test::CLASS);

// index by test.name
$qb $repo->createQueryBuilder('test''test.name');

$result $qb->setMaxResults(10)
    ->
getQuery()
    ->
getResult();

echo 
'QueryBuilder';
dump($result);

// #### DQL ####

$result $entityManager->createQuery(
    
'SELECT test FROM PHPSnippets\Db\Entity\Test test
    INDEX BY test.name'
    
)->setMaxResults(10)
    ->
getResult();

echo 
'DQL';
dump($result);
Result
QueryBuilder
array:3 [
"foo" => Test {#387
+id: 1
+name: "foo"
+creationDate: DateTime {#383
+"date": "2014-07-20 11:37:29.000000"
+"timezone_type": 3
+"timezone": "Europe/Berlin"
}
}
"test" => Test {#392
+id: 2
+name: "test"
+creationDate: DateTime {#393
+"date": "2014-07-20 10:40:22.000000"
+"timezone_type": 3
+"timezone": "Europe/Berlin"
}
}
"bar" => Test {#389
+id: 3
+name: "bar"
+creationDate: DateTime {#390
+"date": "2014-07-23 07:27:18.000000"
+"timezone_type": 3
+"timezone": "Europe/Berlin"
}
}
]

DQL
array:3 [
"foo" => Test {#387
+id: 1
+name: "foo"
+creationDate: DateTime {#383
+"date": "2014-07-20 11:37:29.000000"
+"timezone_type": 3
+"timezone": "Europe/Berlin"
}
}
"test" => Test {#392
+id: 2
+name: "test"
+creationDate: DateTime {#393
+"date": "2014-07-20 10:40:22.000000"
+"timezone_type": 3
+"timezone": "Europe/Berlin"
}
}
"bar" => Test {#389
+id: 3
+name: "bar"
+creationDate: DateTime {#390
+"date": "2014-07-23 07:27:18.000000"
+"timezone_type": 3
+"timezone": "Europe/Berlin"
}
}
]