我在 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.
这里是您可以在上下文中找到该句子的链接。 doctrine official documentation
有人可以给我一个实体之间 ManyToMany
关系中私有(private)实体的示例吗?
最佳答案
假设您将一些用户设置存储在 Settings
中附加到 User
的实体通过一对多或一对一关系的实体,Settings
实体不会在多个用户之间共享,如果引用的用户被删除,也不会被重用,您可以说 Settings
属于 User
私有(private)所有如果 User
就会成为孤儿被删除,orphanRemoval=true
通过删除Settings
来防止这种情况发生当它的“妈妈”User
实体被删除。
关于 SO 的其他一些您可能会感兴趣的问题:
关于多对多关系,可以使用orphanRemoval
在这种关系上, Doctrine 将简单地删除附加实体,即使它们仍然附加到其他实体。
请注意,即使此选项适用于多对多关系,但并未针对此类关系进行正式记录:
- 一对一:http://docs.doctrine-project.org/en/latest/reference/annotations-reference.html#annref-onetoone
- 一对多:http://docs.doctrine-project.org/en/latest/reference/annotations-reference.html#annref-onetomany
- 多对多:http://docs.doctrine-project.org/en/latest/reference/annotations-reference.html#annref-manytomany
我认为没有任何关于多对多关系的私有(private)实体的例子,或者它不会是多对多,但 Doctrine 只是做出了假设确实如此,并且无论如何都会继续删除附加的实体。
关于symfony - "the entities are privately owned"是什么意思(如 Doctrine 官方文档中所示)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27476333/