Reputation: 155
i have entity ShopGoods with relation manyToMany to entity ShopCategory. That's my method for get list of goods:
public function getListByFilter(ShopGoodsFilter $filter) {
$qb = $this->createQueryBuilder('goods')
->select('goods')
->leftJoin('goods.categories', 'categories')
->where('categories.id = :category_id')
->andWhere('goods.status=1')
->andWhere('categories.status != 0') // it's my try...
->setParameter('category_id', $filter->getCategory()->getId())
->setMaxResults($filter->getLimit())
->setFirstResult($filter->getOffset());
return [
'data' => $qb->getQuery()->getResult(),
'total' => $this->getTotalByFilter($filter)
];
}
I can't understand how make condition to get goods with categories.status = 1
for all related categories.
Upvotes: 0
Views: 63
Reputation: 5609
You could use something like:
$qb = $this->createQueryBuilder('goods')
->select('goods')
->leftJoin('goods.categories', 'categories', 'WITH', 'categories.status = 1')
Upvotes: 2