How to limit size of result set in doctrine 2?

blacktie24 picture blacktie24 · Apr 12, 2011 · Viewed 65.1k times · Source

If i'm using the findBy method of the respository class, how can I limit the size of the result set?

Answer

Nikolai Senkevich picture Nikolai Senkevich · May 19, 2011

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

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

example:

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

usage:

$product = $repository->findBy(
    array('name' => 'foo'),
    array('price' => 'ASC'),
    $myLimit,
    $myOffset
);