sBased on Doctrine documentation $qb->getQuery()->execute();
will return a cursor for you to iterator over the results but $qb->find($criteria);
returns the actual found Documents.
I am using symfony2
MongoDBbundle
and I would like to avoid iterating over the 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 I make cutomFunctionWithcreateQueryBuilder()
returns the same class/result as findOneBy
?
Also How can I make execute()
returns all 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();
}
}