将 onDelete 与 Doctrine 2 一起使用 [英] using onDelete with Doctrine 2
问题描述
我无法让 onDelete 在 Doctrine2(使用 YAML 映射)中工作.
I can't get the onDelete to work in Doctrine2 (with YAML Mapping).
我在我的 Product
类中尝试了这种关系:
I tried this relation in my Product
class:
oneToOne:
category:
targetEntity: Category
onDelete: CASCADE
但这不起作用..
我已经在数据库中手动设置了 ON DELETE: CASCADE
I've set the ON DELETE: CASCADE
manually in the database
使用 doctrine:mapping:import
导入 YAML 映射,
imported the YAML mapping with doctrine:mapping:import
,
清空数据库
使用 doctrine:schema:update
从架构更新它,并且在外键中没有 ON DELETE
.. 所以看起来即使是 Doctrine 也不知道如何做吧哈哈..
updated it from the schema with doctrine:schema:update
and got no ON DELETE
in the foreign key.. so looks like even Doctrine doesn't know how to do it lol..
推荐答案
好的,明白了!我不得不在 joinColumn
内使用 onDelete
:
OK, got it! I had to use onDelete
inside joinColumn
:
oneToOne:
category:
targetEntity: Category
joinColumn:
onDelete: CASCADE
这篇关于将 onDelete 与 Doctrine 2 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!