Success! Looks like we've fixed this one. According to our records the fix was applied for EXTJS-11398 in Backlog.
  1. #1
    Sencha User
    Join Date
    Feb 2013
    Posts
    1
    Vote Rating
    0
    ml-jtm is on a distinguished road

      0  

    Default Ext.data.association.HasMany with 'rest' type proxy not passing owner model's id

    Ext.data.association.HasMany with 'rest' type proxy not passing owner model's id


    REQUIRED INFORMATION


    Ext version tested:
    • Ext 4.2.0.663
    Browser versions tested against:
    • Chrome (29.0.1547.76 m)
    Description:

    1st:
    When using a model 'theParent' which has a 'rest' type proxy and a hasMany association to 'theChildren', when the association's store load method is called,

    Code:
    theParent.theChildren().load()
    the resulting rest url &filter[..] section does not contain a 'value' property within the filter object definition

    2nd:
    Need to know how to override the hasMany type for production (minified) extjs


    Steps to reproduce the problem:
    • load a model which has a hasMany association defined
    • Use the auto-generated association method to create the associated store.
    • Attempt to load the associated store ( .load() )
    The result that was expected:

    A http GET for the REST resource:
    • /rest/ml/data/childObj?filter:[{"property": <hasMany association's foreignKey>,"value": <parent's id>}]

    The result that occurs instead:

    A http GET for the REST resource missing the 'value' property of the filter object:
    • /rest/ml/data/childObj?filter:[{"property": <hasMany association's foreignKey>}]
    Test Case:

    https://fiddle.sencha.com/#fiddle/ne

    Code:
        Ext.define("app.model.customer",{
        extend: "Ext.data.Model",
        alias: "model.customer",
        idProperty: "customer_uid",
        fields: [{
            name: "customer_uid",
            type: "integer"
        },
        {
            name: "entity_name",
            type: "string"
        }
        ],
        associations: [
            {
                type: "hasMany",
                model: "app.model.fee_list",
                foreignKey: "customer_uid",
                name: "Fees",
                primaryKey: "fee_uid"
            }
        ],
        proxy: {
            type: "rest",
            url: "./rest/mldev/data/customer",
            reader: {
                type: "json",
                root: "data",
                totalProperty: "totalCount"
            }
        }
    });
    /*
     ...
     After model 'customer' is loaded successfully:
    
    */
    
    var store = customer.Fees(); 
    /*
     When I call customer.Fees(), association entity tries to create associated store B, 
     but CreateStore() method of Ext.data.association.HasMany entity creates wrong filter object
    */
    store.load();
    As this 'fix' works, I have tried to override the Ext.data.association.HasMany class (as I do not want to use the full extjs code in production) but to no avail by including this code:

    Code:
    Ext.override('Ext.data.association.HasMany', {    
        createStore: function() {
            var that            = this,
                associatedModel = that.associatedModel,
                storeName       = that.storeName,
                foreignKey      = that.foreignKey,
                primaryKey      = that.primaryKey,
                filterProperty  = that.filterProperty,
                autoLoad        = that.autoLoad,
                storeConfig     = that.storeConfig || {};
            
            return function() {
                var me = this,
                    config, filter,
                    modelDefaults = {};
                    
                if (me[storeName] === undefined) {
                    if (filterProperty) {
                        filter = {
                            property  : foreignKey, // Old value: filterProperty,
                            value     : me.get(filterProperty),
                            exactMatch: true
                        };
                    } else {
                        filter = {
                            property  : foreignKey,
                            value     : me.get(that.ownerModel.prototype.idProperty), // Old value: me.get(primaryKey),
                            exactMatch: true
                        };
                    }
                    
                    modelDefaults[foreignKey] = me.get(that.ownerModel.prototype.idProperty); // Old value: me.get(primaryKey);
                    
                    config = Ext.apply({}, storeConfig, {
                        model        : associatedModel,
                        filters      : [filter],
                        remoteFilter : false,
                        modelDefaults: modelDefaults
                    });
                    
                    me[storeName] = Ext.data.AbstractStore.create(config);
                    if (autoLoad) {
                        me[storeName].load();
                    }
                }
                
                return me[storeName];
            };
        }
     });


    HELPFUL INFORMATION

    Debugging already done:Possible fix:

    As provided in eLSe's post:

    change code of CreateStore() method in HasMany.js:

    Code:
     
                   if (filterProperty) {                    filter = {
                            property  : foreignKey, // Old value: filterProperty,
                            value     : me.get(filterProperty),
                            exactMatch: true
                        };
                    } else {
                        filter = {
                            property  : foreignKey,
                            value     : me.get(that.ownerModel.prototype.idProperty), // Old value: me.get(primaryKey),
                            exactMatch: true
                        };
                    }
                    
                    modelDefaults[foreignKey] = me.get(that.ownerModel.prototype.idProperty); // Old value: me.get(primaryKey);
    Last edited by Gary Schlosberg; 28 Sep 2013 at 3:54 PM. Reason: Added test fiddle

  2. #2
    Sencha - Support Team
    Join Date
    Feb 2013
    Location
    California
    Posts
    5,035
    Vote Rating
    96
    Gary Schlosberg is just really nice Gary Schlosberg is just really nice Gary Schlosberg is just really nice Gary Schlosberg is just really nice

      0  

    Default


    Thanks for the report! I have opened a bug in our bug tracker.

  3. #3
    Sencha User
    Join Date
    Nov 2013
    Posts
    2
    Vote Rating
    0
    mbTopIT is on a distinguished road

      0  

    Default


    Any news regarding this bug. I have also encountered this and would like to know if the bug was fixed.