Skip to content

Instantly share code, notes, and snippets.

@dimkir
Created February 3, 2016 17:26
Show Gist options
  • Save dimkir/e79b2a878c8e0d6aec29 to your computer and use it in GitHub Desktop.
Save dimkir/e79b2a878c8e0d6aec29 to your computer and use it in GitHub Desktop.
Attempt to limit quantity of loaded relationships (eg. only load 5 presentations with the Category)
<?php
namespace AppBundle\Repository;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Tools\Pagination\Paginator;
class CategoryRepository extends EntityRepository
{
function getCategoryWithGivenAmountOfPresentations($limit = 5, $offset = 0){
$em = $this->getEntityManager();
$dql = <<< EOF
SELECT cat,prezis FROM AppBundle:Category cat
JOIN cat.presentations prezis
EOF;
$query = $em->createQuery($dql)
->setFirstResult($offset)
->setMaxResults($limit);
$paginator = new Paginator($query, $fetchJoinCollection = true);
// $c = count($paginator);
return $paginator;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment