I've created self-referenced category entity, product entity with many-to-many relationship to category entity.
Example categories list:
MacBooks -MacBook Air --MacBook Air 11 --MacBook Air 13 -MacBook Pro --MacBook Pro 13 I'm getting products based on selected category.
public function getByCategory($category) { $qb = $this->createQueryBuilder('p'); $qb->leftJoin('p.categories', 'c'); $qb->where('c.url = :category'); $qb->setParameter('category', $category); return $qb->getQuery()->useQueryCache(true); } For example product is inside a category MacBook Air 13.
So my code works only if I select the category MacBook Air 13.
But how to show products in parent category? For example in category MacBook Air I want to display products from categories MacBook Air 11 and MacBook Air 13, etc...
Same in category MacBooks display everything from MacBook Air, MacBook Air 11, MacBook Air 13, etc...?
Question simplification: How to get all products from all children.
MacBook -> MacBook Air -> MacBook Air 11, MacBook Air 13