Status/Resolution/Reason: To Fix//Investigate
Reporter/Name(from Bugbase): Luis Majano / Luis Majano (Luis Majano)
Created: 04/04/2014
Components: ORM Support
Versions: 11.0
Failure Type: Enhancement Request
Found In Build/Fixed In Build: PublicBeta /
Priority/Frequency: Trivial / Unknown
Locale/System: English / Mac All
Vote Count: 0
Right now as it stands, you have to code a tremendous amount of boilerplate code in order to have bi-directional relationships work from either side. Why not add this already to the generated functions already, it makes no sense from a productivity standpoint to not do this and it should be simple enough.
Let's say I have a menu -> menuItems (one-to-many) and menuItems has many-to-one. The menu has the inverse relationship:
// O2M -> Comments
property name="menuItems"
singularName="menuItem"
fieldtype="one-to-many"
type="array"
cfc="contentbox.model.menu.item.BaseMenuItem"
fkcolumn="FK_menuID"
cascade="all-delete-orphan"
inverse="true"
lazy="extra";
Once I have defined this relationship I have to constantly create the following methods:
/**
* @Override due to bi-directional relationships
*/
Menu function addMenuItem( required menuItem ){
// add them to the local array
arrayAppend( variables.menuItems, arguments.menuItem );
// set the bi-directional relation
arguments.menuItem.setMenu( this );
return this;
}
/**
* @Override due to bi-directional relationships
*/
Menu function setMenuItems( required array menuItems ){
if( hasMenuItem() ){
// manual remove, so hibernate can clear the existing relationships
variables.menuItems.clear();
// Add the incoming ones to the same array
variables.menuItems.addAll( arguments.menuItems );
} else {
variables.menuItems = arguments.menuItems;
}
return this;
}
They are always the same for ANY one-to-many relationships or many-to-many relationships. It would be a huge productivity boost if this is already done by CF.
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 3737411
External Customer Info:
External Company:
External Customer Name: LuisMajano
External Customer Email:
External Test Config: My Hardware and Environment details:
Attachments:
Comments: