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 {#396
+id: 1
+name: "foo"
+creationDate: DateTime @1405849049 {#392
date: 2014-07-20 11:37:29.0 Europe/Berlin (+02:00)
}
}
"test" => Test {#401
+id: 2
+name: "test"
+creationDate: DateTime @1405845622 {#402
date: 2014-07-20 10:40:22.0 Europe/Berlin (+02:00)
}
}
"bar" => Test {#398
+id: 3
+name: "bar"
+creationDate: DateTime @1406093238 {#399
date: 2014-07-23 07:27:18.0 Europe/Berlin (+02:00)
}
}
]

DQL
array:3 [
"foo" => Test {#396
+id: 1
+name: "foo"
+creationDate: DateTime @1405849049 {#392
date: 2014-07-20 11:37:29.0 Europe/Berlin (+02:00)
}
}
"test" => Test {#401
+id: 2
+name: "test"
+creationDate: DateTime @1405845622 {#402
date: 2014-07-20 10:40:22.0 Europe/Berlin (+02:00)
}
}
"bar" => Test {#398
+id: 3
+name: "bar"
+creationDate: DateTime @1406093238 {#399
date: 2014-07-23 07:27:18.0 Europe/Berlin (+02:00)
}
}
]
Used Versions
PHP 7.2, Zend 3.0, Symfony 4.0, Laravel 5.6, PHPUnit 6.5, Doctrine 2.8