我正在写一个Shopware插件。 Shopware使用Doctrine for Database操作。
我想写一个这样的学说:
Where(condition1 and [condition2 or condition3])
在代码中查看我的评论。
$builder = Shopware()->Models()->createQueryBuilder();
$builder->select([
'orders',
'details',
'customer',
'shipping',
'billing'
]);
$builder->from('Shopware\Models\Order\Order', 'orders');
$builder->leftJoin('orders.details', 'details')
->leftJoin('orders.customer', 'customer')
->leftJoin('orders.shipping', 'shipping')
->leftJoin('orders.billing', 'billing');
//--> Here I would like to write an or statement.
// So that i get all the orders by
// where(customers.email = email) and [(shipping.zipCode = zip) or (billing.zipcode = zip)]
$builder->where('customer.email = :email');
$builder->andWhere('(shipping.zipCode = :zipCode) orWhere (billing.zipCode = :zipCode)');
$builder->setParameter('email', $email);
$builder->setParameter('zipCode', $zip);
$builder->orderBy('orders.id', 'DESC');
$order = $builder->getQuery()->getResult($this->getResultMode());
答案 0 :(得分:2)
使用:
$builder->where('customer.email = :email');
$builder->andWhere('(shipping.zipCode = :zipCode OR billing.zipCode = :zipCode)')
除了单一条件,where
采用任何形式的条件