symfony - Why Doctrine MongoDB ODM findBy and execute returns different classes? -
sbased on doctrine documentation $qb->getquery()->execute();
return cursor iterator on results $qb->find($criteria);
returns actual found documents.
i using symfony2
mongodbbundle
, avoid iterating on result set in repository
classes.
// returns product document $entity = $this->get('doctrine_mongodb') ->getrepository("mybundle:product") ->findoneby(array('title' => 'somthing')); // returns cursor $entity = $this->get('doctrine_mongodb') ->getrepository("mybundle:product") ->customfunctionwithcreatequerybuilder(array('title' => 'somthing'));
how can make cutomfunctionwithcreatequerybuilder()
returns same class/result findoneby
?
also how can make execute()
returns embedded documents?
edit
content of cutomfunctionwithcreatequerybuilder:
class productrepository extends documentrepository { public function customfunctionwithcreatequerybuilder($param, $hydrate = true) { $query = $this->createquerybuilder() ->select() ->hydrate($hydrate); if (isset($param['unique_id'])) { $query->field('id')->equals($param['unique_id']); } return $query->getquery()->execute(); } }
you can use getsingleresult()
if want 1 result , set eagercursor true data @ once. in example:
[...] if (isset($param['unique_id'])) { $query->field('id')->equals($param['unique_id']); } return $query->eagercursor(true)->getquery()->getsingleresult(); [...]
Comments
Post a Comment