Created
February 3, 2016 17:26
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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