Doctrine where Query- 逻辑顺序 - Where(condition1 and [condition2 or condition3])
Doctrine where Query- Logical order - Where(condition1 and [condition2 or condition3])
我目前正在编写一个 Shopware 插件。 Shopware 使用 Doctrine 进行数据库操作。
我想写这样的学说:
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());
使用:
$builder->where('customer.email = :email');
$builder->andWhere('(shipping.zipCode = :zipCode OR billing.zipCode = :zipCode)')
除了单一条件,where
接受任何 形式的条件
我目前正在编写一个 Shopware 插件。 Shopware 使用 Doctrine 进行数据库操作。
我想写这样的学说:
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());
使用:
$builder->where('customer.email = :email');
$builder->andWhere('(shipping.zipCode = :zipCode OR billing.zipCode = :zipCode)')
除了单一条件,where
接受任何 形式的条件