Answer the question
In order to leave comments, you need to log in
How to write a query in doctrine?
I work in Symfony2.
I have two entities
class CategoryRepository extends EntityRepository
{
public function findAll()
{
return $this->createQueryBuilder('c')
->innerJoin('c.items', 'i')
->where('i.isActive = 1')
->orderBy('c.position', 'ASC')
->getQuery()->getResult();
}
}
Answer the question
In order to leave comments, you need to log in
I would do this with two requests: the first one is pulling out the ID of all categories, the second one is pulling out all the categories with their items.
Pure SQL example:
SELECT DISTINCT(category_id)
FROM items
WHERE is_active = 1;
SELECT *
FROM categories c
INNER JOIN items i
ON (i.category_id = c.id)
WHERE c.id IN (categoriesIDS)
ORDER BY c.position ASC;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question