我将实体ShopGoods与manyToMany关联到实体ShopCategory。这是获取商品清单的方法:
.png
我无法理解如何使用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)
];
}
获取所有相关类别的商品。
答案 0 :(得分:2)
您可以使用以下内容:
$qb = $this->createQueryBuilder('goods')
->select('goods')
->leftJoin('goods.categories', 'categories', 'WITH', 'categories.status = 1')