且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

关于使用 dotric2 删除级联

更新时间:2023-02-02 22:41:42

Doctrine中有两种cascades:

There are two kinds of cascades in Doctrine:

1) ORM级别——在关联中使用cascade={"remove"}——这是在UnitOfWork中完成的计算,不影响数据库结构.当您移除一个对象时,UnitOfWork 将遍历关联中的所有对象并将其移除.

1) ORM level - uses cascade={"remove"} in the association - this is a calculation that is done in the UnitOfWork and does not affect the database structure. When you remove an object, the UnitOfWork will iterate over all objects in the association and remove them.

2) 数据库级别 - 在关联的 joinColumn 上使用 onDelete="CASCADE" - 这会将 On Delete Cascade 添加到数据库中的外键列:

2) Database level - uses onDelete="CASCADE" on the association's joinColumn - this will add On Delete Cascade to the foreign key column in the database:

@ORMJoinColumn(name="father_id", referencedColumnName="id", onDelete="CASCADE")

我还想指出,您现在拥有级联 ={"remove"} 的方式,如果您删除子对象,此级联将删除父对象.显然不是你想要的.

I also want to point out that the way you have your cascade={"remove"} right now, if you delete a Child object, this cascade will remove the Parent object. Clearly not what you want.