bi-directional o2m/m2o beats uni-directional o2m in SQL efficiency?
        Posted  
        
            by Henry
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Henry
        
        
        
        Published on 2010-03-05T20:58:45Z
        Indexed on 
            2010/03/09
            1:36 UTC
        
        
        Read the original article
        Hit count: 427
        
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?
© Stack Overflow or respective owner