主义:级联=“删除” vs orphanremoval = true [英] Doctrine: cascade="remove" vs orphanremoval=true

查看:334
本文介绍了主义:级联=“删除” vs orphanremoval = true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上述2个选项有什么区别?什么时候最好选择每个选项?

What is the difference between the 2 options above? When is it preferable to choose each option?

推荐答案

它们之间的基本区别是:

The basic difference between them is:


当使用orphanRemoval = true选项时,Doctrine假设
这些实体是私有的,不会被其他
实体重用。如果忽略了这一假设,即使您将孤立实体分配给
另一个实体,您的实体将获得由Doctrine删除的

When using the orphanRemoval=true option Doctrine makes the assumption that the entities are privately owned and will NOT be reused by other entities. If you neglect this assumption your entities will get deleted by Doctrine even if you assigned the orphaned entity to another one.

说出你的 用户 注释 。如果您使用 cascade =remove,则可以删除 注释的引用 用户 ,然后将 评论 附加到另一个 用户 。当你坚持下去,他们将被正确保存。但是,如果您使用 orphanRemoval = true ,即使您将删除给定的 评论 一个 用户 ,然后附加到另一个 用户 由于引用已被删除,因此该注释将被删除。

Say your User has one-to-many relation to Comment. If you are using cascade="remove", you can remove the reference for Comment from one User, and then attach that Comment to another User. When you persist them, they will be correctly saved. But if you are using orphanRemoval=true, even if you will remove given Comment from one User, and then attach to another User, this comment will be deleted during persist, because the reference has been deleted.

这篇关于主义:级联=“删除” vs orphanremoval = true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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