双向o2m/m2o在SQL效率上优于单向o2m?

发布于 2024-08-24 00:20:10 字数 776 浏览 6 评论 0原文

使用这 2 个持久性 CFC 例如:

// Cat.cfc
component persistent="true" {
  property name="id" fieldtype="id" generator="native";
  property name="name";
}

// Owner.cfc
component persistent="true" {
  property name="id" fieldtype="id" generator="native";
  property name="cats" type="array" fieldtype="one-to-many" cfc="cat" cascade="all";
} 

当一对多(单向)时注意:单向上的 inverse=true 将产生不需要的结果

insert into cat (name) values        (?)
insert into Owner default values
update cat set Owner_id=? where id=?

当一对多/多对一(双向)时-direction, inverse=true on Owner.cats):

insert into Owner default  values
insert into cat (name, ownerId) values (?, ?) 

这是否意味着首选设置双向 o2m/m2o 关系,因为插入实体的 SQL 效率更高?

Use these 2 persistent CFCs for example:

// Cat.cfc
component persistent="true" {
  property name="id" fieldtype="id" generator="native";
  property name="name";
}

// Owner.cfc
component persistent="true" {
  property name="id" fieldtype="id" generator="native";
  property name="cats" type="array" fieldtype="one-to-many" cfc="cat" cascade="all";
} 

When one-to-many (unidirectional) Note: inverse=true on unidirectional will yield undesired result:

insert into cat (name) values        (?)
insert into Owner default values
update cat set Owner_id=? where id=?

When one-to-many/many-to-one (bi-directional, inverse=true on Owner.cats):

insert into Owner default  values
insert into cat (name, ownerId) values (?, ?) 

Does that mean setting up bi-directional o2m/m2o relationship is preferred 'cause the SQL for inserting the entities is more efficient?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

双手揣兜 2024-08-31 00:20:10

“首选”很复杂。

虽然对于“猫”来说,默认所有者的想法没有意义,但对于工厂或商店的情况可能有意义,一旦创建“产品”,它就会获得“工厂”的默认“位置”。

'Preferred' is complicated.

While for 'cat' the idea of a default owner doesn't make sense, it might do for a factory or shop situation, where once a 'product' is created it get's a default 'location' of 'the factory'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文