3

我有以下查询:

  $em = $this->getEntityManager();
        $query = $em->createQueryBuilder()->select('shoppingcart')
            ->from("AppMainBundle:ShoppingCart", 'shoppingcart')
            ->innerJoin('shoppingcart.shoppingCartProducts', 'shoppingcartproduct')
            ->innerJoin('shoppingcartproduct.product', 'product')
            ->innerJoin('shoppingcartproduct.productAttribute', 'productattribute')
            ->innerJoin('product.shop', 'shop')
            ;

如何编写 where 语句,我只想获取其中包含多个购物车产品的购物车?这里是购物车和购物车产品的关系:

class ShoppingCart
{
    /**
     * @var integer $id
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;



    /**
     * @ORM\OneToMany(targetEntity="ShoppingCartProduct", mappedBy="shoppingCart", cascade={"persist","remove"})
     */
    protected $shoppingCartProducts;
}
4

1 回答 1

3

尝试添加以下行

->addSelect('COUNT(shoppingcartproduct) as nProducts')
->addGroupBy('shoppingcart.id')
->having('nProducts > 1')
于 2013-09-07T04:10:03.403 回答