说我有以下课程:
class Store { /** * @ManyToMany(targetEntity="PaymentMethod") */ protected $paymentMethods; } class PaymentMethod { }
当我们删除(或者只是禁用,而不是实际从数据库中删除)PaymentMethod时,我们希望从所有Store :: $paymentMethods集合中删除此paymentMethod.
到目前为止,我们一直在联结表上使用原始SQL查询:
DELETE FROM StorePaymentMethod WHERE paymentMethodId = ?
有没有办法在Doctrine中做到这一点,最好是在DQL中?
沿着这些方向的东西?
$qb = $em->createQueryBuilder(); $qb->delete('StorePaymentMethod','spm') ->where('spm.paymentMethodId = : paymentMethodId') ->setParameter('paymentMethodId',$id); return $qb->getQuery()->getResult();