我有以下查询:
$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语句,我只想获得包含多个shoppingcartproduct的shoppingcart?这是购物车和购物车产品的关系:
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;
}
答案 0 :(得分:2)
尝试添加以下行
->addSelect('COUNT(shoppingcartproduct) as nProducts')
->addGroupBy('shoppingcart.id')
->having('nProducts > 1')