php - Doctrine Query Builder : Result returning array of two times the same result -
i'm working on symfony project, using doctrine manage entities.
i have table named user, containing few columns, , table named tag, containing foreign key user table manytoone relation based on user id, , single other column named value.
in app, need find list of users, depending on 1 of tag row, , value of 1 of user's column. let's resume :
select users user.value equals somevalue , tag.value equals anothervalue.
as never used symfony nor doctrine before project, searched doctrine documentation , found query builder. so, did :
edit : way doing kinda weird, modified , here result :
public function findbytagandapp($tag, $app) { $em = $this->getentitymanager(); $qb = $em ->getrepository('apibundle:user') ->createquerybuilder('u') ->leftjoin('apibundle\entity\tag', 't') ->where('u.application = :app') ->andwhere('t.tag = :tag') ->setparameter('tag', $tag) ->setparameter('app', $app) ; $users = $qb->getquery()->getresult(); return $users; }
and seems works, in strange way. instead of returning array of user items, want, returns array of array of user items. first array containing 2 entries, , these 2 entries identical : array need, without single difference.
i tried return $users[0] instead of users, , can manipulate user entities intended way. keep way working, i'd know why returns unneeded array of array instead of array want. might query, i'm not sure how modify users want.
any clues on why behave appreciated, i'm still learning doctrine. !
edit² : nevermind, query seems incorrect too, got users according $app value, seems never check if there row in tag table value of somevalue associated foreign key of user table..
i don't know why but.. think have mention from() ->from('user', 'u')
can find here
Comments
Post a Comment