Doctrine2 createNativeQuery returns an object with one result when there are more -
i have following doctrine2 code:
$sql = 'select user_name, user_email users'; $rsm = new resultsetmapping(); $rsm->addentityresult('entity\users', 'u'); $rsm->addfieldresult('u', 'user_name', 'username'); $rsm->addfieldresult('u', 'user_email', 'useremail'); $query = $this->em->createnativequery($sql, $rsm); $users = $query->getresult();
which returns array 1 item first user. however, if change
$users = $query->getarrayresult();
it returns full set of users expected. can see problem here?
thanks!
p.s. yes, know simple query doesn't require createnativequery, real query complex querybuilder or dql, , have simplified see whether problem query. isn't.
the arrayhydrator
(used getarrayresult
) checks if query has 1 entityresult mapping, if continues populate result array after identifiermap has been set entityresult alias. objecthydrator
(used getresult
) not perform check, whatever reason, stops populating array after setting first value.
you can see looking @ arrayhydrator->_issimplequery
Comments
Post a Comment