双向o2m/m2o在SQL效率上优于单向o2m?
使用这 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“首选”很复杂。
虽然对于“猫”来说,默认所有者的想法没有意义,但对于工厂或商店的情况可能有意义,一旦创建“产品”,它就会获得“工厂”的默认“位置”。
'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'.