英文:
Doctrine - how to prevent cascade action in testing environment
问题
我有这段代码:
class Event {
/**
* @ORM\ManyToOne(targetEntity=Supplier::class, inversedBy="events", cascade={"persist","remove"})
* @ORM\JoinColumn(onDelete="SET NULL")
**/
private $supplier;
...
}
当删除事件时,条件cascade={"persist","remove"}
使得供应商也被删除。
我想仅在我的测试环境中更改此行为。
有没有什么技巧可以做到这一点?如果没有,我将不得不在每次删除事件时重新创建供应商....
英文:
I have this chunk of code :
class Event {
/**
* @ORM\ManyToOne(targetEntity=Supplier::class, inversedBy="events", cascade={"persist","remove"})
* @ORM\JoinColumn(onDelete="SET NULL")
**/
private $supplier;
...
}
When an Event is deleted, the condition cascade={"persist","remove"}
makes that the supplier is also deleted.
I would like to change this behavior only for my testing environment.
Is there a trick to do this ? if not, I will have to recreate the supplier each time an event is deleted....
答案1
得分: 1
我没有找到实现我想要的方式,但我唯一的解决方案是在删除事件之前将属性$supplier
设置为null
,这样就不会对任何供应商进行级联删除。
英文:
I did not find a way to do what I want, but the only solution I had was to set the property $supplier
to null
before deleting the event, so there's no cascade removing on any supplier.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论