How exactly to use onDelete = quot;SET NULLquot; - Doctrine2(如何准确地使用 onDelete = “SET NULL?- 教义2)
问题描述
我有一个 Category 类包含这个:
I have a class Category containing this:
/**
* @ORMOneToMany(targetEntity="Friend", mappedBy="category")
* @ORMOrderBy({"name" = "ASC"})
*/
protected $friends;
和一个班级朋友:
/**
* @ORMManyToOne(targetEntity="Category", inversedBy="friends")
* @ORMJoinColumn(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,我尝试了上面显示的内容,我尝试使用 cascade={"remove"}
在 OneToMany 注释中,但没有任何效果!我也找不到例子.你能帮我吗?
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何准确地使用 onDelete = “SET NULL"?- 教义2


- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01