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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -