Doctrine2类表继承和级联删除 [英] Doctrine2 Class Table Inheritance and Cascading Delete

查看:96
本文介绍了Doctrine2类表继承和级联删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与Dofrine2.2.2一起使用Symfony 2.0.15。我注意到,当使用Class Table Inheritance时,例如:

I'm working with Doctrine2.2.2 in conjunction with Symfony 2.0.15. I notice that when using Class Table Inheritance, for example:

/**
 * @Entity
 * @InheritanceType("JOINED")
 * @DiscriminatorColumn(name="discr", type="string")
 * @DiscriminatorMap({"person" = "Person", "employee" = "Employee"})
 */

这将创建一个外键级联删除约束对孩子实体/表(在这种情况下为Employee)。 Doctrine的文件这个包含一个重要的黄色框,内容如下:

this will create a foreign key cascading delete constraint on child entities/tables (in this case Employee). Doctrine's documentation on this contains an important-looking yellow box that reads:


当您不使用SchemaTool生成所需的SQL时
应该知道,删除类表继承使用
外键属性ON DELETE CASCADE在所有数据库
实现。无法实现这一点,将导致数据库中的
死线。

When you do not use the SchemaTool to generate the required SQL you should know that deleting a class table inheritance makes use of the foreign key property ON DELETE CASCADE in all database implementations. A failure to implement this yourself will lead to dead rows in the database.

哪些对我没有意义。这是否意味着如果您不使用SchemaTool,则Doctrine将创建外键级联删除约束?如果使用SchemaTool,Doctrine会否使用内置的级联功能?

Which doesn't make sense to me. Does this mean that if you don't use the SchemaTool then Doctrine will create the foreign key cascading delete constraint? If one did use the SchemaTool, would Doctrine use it's built-in cascade capabilities instead?

推荐答案

是什么意思,您使用SchemaTool生成SQL,它还将向您的外键约束添加适当的ON DELETE CASCADE部分。

What is is saying is that when you generate the SQL with the SchemaTool, it will also add the appropriate ON DELETE CASCADE part to your foreign key constraint.

ALTER TABLE Employee ADD CONSTRAINT FK_55D6C234BF396750 
    FOREIGN KEY (id) REFERENCES Parent(id) ON DELETE CASCADE;

如果不使用SchemaTool,则需要确保外键约束具有ON DELETE CASCADE part,或者当您从Employee表中删除行时,您的父表格中将出现孤立行。

If you don't use the SchemaTool, you need to make sure that the foreign key constraint has the ON DELETE CASCADE part, or when you delete rows from the Employee table you will end up with orphaned rows in your parent table.

这篇关于Doctrine2类表继承和级联删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆