如何使用onDelete =“SET NULL” - 教义2 [英] How exactly to use onDelete = "SET NULL" - Doctrine2
问题描述
我有一个类类别,包含以下内容:
I have a class Category containing this:
/**
* @ORM\OneToMany(targetEntity="Friend", mappedBy="category")
* @ORM\OrderBy({"name" = "ASC"})
*/
protected $friends;
和一个类朋友:
/**
* @ORM\ManyToOne(targetEntity="Category", inversedBy="friends")
* @ORM\JoinColumn(name="category_id", referencedColumnName="id", onDelete="SET NULL")
*/
protected $category;
我想要的是删除类别,无论是否有这个类别的朋友,如果有 - 这个朋友的类别字段被设置为NULL。
What I want is to be able to delete categories no matter if there are some friends from this category, and if there are - the category field for this friends to be set to NULL.
我试图把 onDelete =CASCADE
到ManyToOne注释,然后到OneToMany,我尝试了上面显示的内容,我尝试在OneToMany注释中使用 cascade = {remove}
,没有任何工作!我也找不到一个例子。你可以帮助我吗?
I tried to put onDelete="CASCADE"
to the ManyToOne annotation, then to the OneToMany, I tried what is shown above, I tried using cascade={"remove"}
in the OneToMany annotation, and nothing worked! I couldn't find a example as well. Could you please help me?
推荐答案
这必须是一个疯狂的答案,但是你更新了数据库模式? onDelete =SET NULL
在数据库级别,它必须适用于innoDB。
This must be a crazy answer but did you update database schema? onDelete="SET NULL"
is on database level, it must work on innoDB.
这篇关于如何使用onDelete =“SET NULL” - 教义2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!