如何在 Doctrine 2 中批量删除多对多关系中的实体?
假设我有以下类:
class Store
{
/**
* @ManyToMany(targetEntity="PaymentMethod")
*/
protected $paymentMethods;
}
class PaymentMethod
{
}
当我们删除(或只是禁用,而不是实际从数据库中删除)一个 PaymentMethod
时,我们希望这个 paymentMethod
从所有类中删除Store::$ paymentMethods
集合。
到目前为止,我们一直在联结表上使用原始 SQL 查询来实现此目的:
DELETE FROM StorePaymentMethod WHERE paymentMethodId = ?
有没有办法在 Doctrine 中(最好是在 DQL 中)执行此操作?
Say I have the following classes:
class Store
{
/**
* @ManyToMany(targetEntity="PaymentMethod")
*/
protected $paymentMethods;
}
class PaymentMethod
{
}
When we delete (or just disable, without actually removing from the database) a PaymentMethod
, we'd like that this paymentMethod
gets removed from all the Store::$paymentMethods
collections.
Up to now, we've been using raw SQL queries on the junction table for this:
DELETE FROM StorePaymentMethod WHERE paymentMethodId = ?
Is there a way to do that in Doctrine, preferably in DQL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
沿着这些思路的东西?
Something along these lines ?