为什么建议在ORM中避免双向关系? [英] Why is it recommended to avoid bidirectional relations in ORM?

查看:68
本文介绍了为什么建议在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?)

来源:

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/best-practices.html#constrain-relationships-as-much-as-possible

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屋!

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