How to limit the size of the result established in doctrine 2?

If I use the findBy method of the repository class, how can I limit the size of the result set?

+47
php orm doctrine2 doctrine-orm
Apr 12 '11 at 19:50
source share
3 answers

In the Doctrine 2.1 method, EntityRepository # findBy () now accepts additional parameters for ordering, constraint, and offset.

see the full list of new features in doctrine 2.1 (404) Related link to findBy and findOneBy

Example:

public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) 

using:

 $product = $repository->findBy( array('name' => 'foo'), array('price' => 'ASC'), $myLimit, $myOffset ); 
+118
May 19 '11 at 9:19
source share

For the Doctrine Query Language you have:

 QueryBuilder::setMaxResults(integer $maxResults) 
+4
Nov 13 '11 at 23:23
source share

The findBy () method of the shared repository class does not support this.

I would write my own repository (as described here ) and override findBy () to take extra parameters. Your new implementation may use query builder or simple-DQL to create the correct query. (I would use querybuilder, since you can probably just pass the $ critera parameter directly to QueryBuilder :: where () )

+3
Apr 12 '11 at 20:29
source share



All Articles