Skip to content

Instantly share code, notes, and snippets.

@araines
Created February 7, 2017 15:03
Show Gist options
  • Save araines/b2f64a8732ba68ecd2a8c47aaf63c6cb to your computer and use it in GitHub Desktop.
Save araines/b2f64a8732ba68ecd2a8c47aaf63c6cb to your computer and use it in GitHub Desktop.
<?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