i have tried select fields with doctrine query buidler.
$queryBuilder = $entityManager->createQueryBuilder();
$queryBuilder->select('au.id, au.firstName')
->from('Api\V1\Entity\AgencyUser', 'au')
->orderBy('au.firstName', 'asc');
$queryBuilder->andWhere('au.agency = :agencyId')
->setParameter('agencyId', $agency->getId());
print_r($queryBuilder->getQuery()->getResult(Query::HYDRATE_OBJECT));exit;
result :
Array
(
[0] => Array
(
[id] => 1
[firstName] => agency
)
)
why this is an array ? i want to hydrated result. any idea ?
You want to use Doctrine's Partial Object Syntax
As to why it's not returning an object, this is from the same documentation linked above: