Doctrine: Restricted FetchAll ()

I want to do fetchAll () with a limit? Do you know if this is possible with the symfony2 entity manager?

My current code (Fetch all, no limit):

$repository = $this->getDoctrine()->getRepository('MyBundle:Download'); $product = $repository->findAll(); 

Thanks to everyone. Best wishes,

EDIT:

 $em = $this->getDoctrine()->getRepository('MyBundle:Download'); $ouput = $em->findBy(array(), array('id' => 'DESC'),5); 

Return the last 5 lines.

Thanks to everyone.

+7
symfony entitymanager doctrine2
source share
1 answer

It is often instructive to check the source code.

 Doctrine\ORM\EntityRepository public function findAll() { return $this->findBy(array()); } public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) { $persister = $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName); return $persister->loadAll($criteria, $orderBy, $limit, $offset); } 
+37
source share

All Articles