为什么建议在ORM中避免双向关系? [英] Why is it recommended to avoid bidirectional relations in ORM?
问题描述
不建议实体之间建立双向关系的技术原因是什么?它会影响ORM的性能吗? (如果是这样,为什么?)
What are the technical reasons that bidirectional relations between entities are not recommended? Does it impact an ORM's performance? (If so, why?)
来源:
https://ocramius.github.io/doctrine-best-practices /#/86
推荐答案
在您提到的第一个来源中,提到了三个原因:
In that first source you refer to are three reasons mentioned:
这有几个好处:
This has several benefits:
- 减少域模型中的耦合
- 您的域模型中的代码更简单(无需正确地保持双向性)
- 少说教义
- Reduced coupling in your domain model
- Simpler code in your domain model (no need to maintain bidirectionality properly)
- Less work for Doctrine
第二个:
双向关联非常重要
BI-DIRECTIONAL ASSOCIATIONS ARE OVERHEAD
我认为这就是原因. 少做一些工作" 和 是多余的" 知道还有其他解释方式...
I assume those are the whys. "Less work doctrine" and "are overhead" most likely means that it impacts performance, I wouldn't know how else to interpret that...
之所以有意义,是因为只要您在双向关系中更改某些内容,ORM就需要更新双方.
Makes sense since the ORM needs to update both sides whenever you change something in a bi-directional relationship.
这篇关于为什么建议在ORM中避免双向关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!