2017-08-25 43 views
0

我有實體ShopGoods,其關係manyToMany與實體ShopCategory相關。這是我對商品的獲取列表方法:symfony3學說。爲相關記錄創造條件

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) 
    ]; 
} 

我不明白如何使病情得到貨物categories.status = 1所有相關類別。

+0

看起來沒給我,你可以發佈生成的SQL? – Xymanek

+0

對我來說也不錯 –

回答

2

您可以使用類似:

$qb = $this->createQueryBuilder('goods') 
    ->select('goods') 
    ->leftJoin('goods.categories', 'categories', 'WITH', 'categories.status = 1')