Created
February 7, 2017 15:03
-
-
Save araines/b2f64a8732ba68ecd2a8c47aaf63c6cb to your computer and use it in GitHub Desktop.
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 | |
class FooRepository extends EntityRepository | |
{ | |
public function findCategories() | |
{ | |
return $this->getCategoriesQueryBuilder() | |
->getQuery() | |
->getResult(); | |
} | |
public function findCategoriesWithMedia() | |
{ | |
return $this->getCategoriesQueryBuilder() | |
->addSelect('m') | |
->leftJoin('p.medias', 'm') | |
->getQuery() | |
->getResult(); | |
} | |
private function getCategoriesQueryBuilder() | |
{ | |
return $this->getEntityManager()->createQueryBuilder() | |
->select(['c', 'p', 'm']) | |
->from('AppBundle:FeatureProduct', 'c') | |
->join('c.product', 'p') | |
->join('p.category', 'a') | |
->orderBy('c.id', 'DESC'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment