开发者

bi-directional o2m/m2o beats uni-directional o2m in SQL efficiency?

开发者 https://www.devze.com 2022-12-22 05:35 出处:网络
Use these 2 persistent CFCs for example: // Cat.cfc component persistent=\"true\" { property name=\"id\" fieldtype=\"id\" generator=\"native\";

Use these 2 persistent CFCs for example:

// Cat.cfc
component persistent="true" {
  property name="id" fieldtype="id" generator="native";
  p开发者_如何转开发roperty 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?


'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'.

0

精彩评论

暂无评论...
验证码 换一张
取 消