doctrine2 - How to fetch all in orm symfony? -
i'm trying list of users query
$userlist = [1,5,2,3,1]; $users = $this->getentitymanager()->getrepository('appbundle:user')->findby(['id' => $userlist]);
this code working distinct user. display this
--------------- userid | name --------------- 1 | 5 | ace 2 | red 3 | ran
but want display one
--------------- userid | name --------------- 1 | 5 | ace 2 | red 3 | ran 1 |
how can in orm?
update
i try one.
public function getusers($id) { $query = $this->createquerybuilder('u') ->addselect('u') ->distinct(false) ->where('u.id in (:ulist)') ->setparameter('ulist', $id) ->getquery(); $users = $query->getresult(query::hydrate_array); return $users; }
but display same
you can try query builder.
$repository = $this->getdoctrine()->getrepository('appbundle:user'); $query = $repository->createquerybuilder('u') ->select('u') ->where('u.id in (:ulist)') ->setparameter('ulist', $userlist) ->getquery(); $users = $query->getresult();
if still gets distinct results try this
$repository = $this->getdoctrine()->getrepository('appbundle:user'); $query = $repository->createquerybuilder('u') ->select('u') ->distinct(false) ->where('u.id in (:ulist)') ->setparameter('ulist', $userlist) ->getquery(); $users = $query->getresult();
otherwise you'll have create array of objects. can replacing last line with
$users = $query->getresult(query:hydrate_array);
now have multidimensional array records, , can display them many want want fetching them $users[0]['username'] example
Comments
Post a Comment