tracker issue : CF-3737411

select a category, or use search below
(searches all categories and all time range)
Title:

ORM bi-directional relationship setup

| View in Tracker

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:

What do you mean never fix?
Comment by External U.
12856 | September 14, 2014 11:24:43 AM GMT
Changed it to ToFix. Had misunderstood the enhancement request. Thanks for the follow-up. I noticed you are setting the bi-directional relationship in addMenuItem but not in setMenuItems. Doesn't it make sense?
Comment by Himavanth R.
12857 | September 16, 2014 12:29:24 AM GMT
FYI, hibernate 4/5 added this as a simple byte weaving option, you just need to enable it in configuration.
Comment by Luis M.
12858 | April 13, 2017 04:38:41 PM GMT