You found a bug! We've classified it as TOUCH-4608 . We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
  1. #1
    Sencha User
    Join Date
    Dec 2012
    Location
    Hamburg, Germany
    Posts
    11
    Vote Rating
    0
    emste is on a distinguished road

      0  

    Default Wrong arguments passed to HasOne association success method

    Wrong arguments passed to HasOne association success method


    REQUIRED INFORMATION

    Ext version tested:
    • ST 2.2.1
    Browser versions tested against:
    • Chrome 27
    Description:
    • The "success" callback defined inside an options object to load a has-one association of a model gets an [object Arguments] as first and only parameter. Inside this Arguments parameter are the "true" parameters that should be passed.
    Steps to reproduce the problem:
    • Create a model A
    • Add model B to A as an has-one association
    • Load model B by executing A.getB({ success: function() {} })
    The result that was expected:
    • success beeing called with model B as first parameter and an operation object as second parameter, as stated in the documentation
    The result that occurs instead:
    • success is beeing called with [object Arguments] as first parameter, having the desired parameters in it
    Possible fix:
    • Maybe Function.call is used instead of Function.apply
    Example Code:
    Code:
    Ext.define('ModelA', {
        extend: 'Ext.data.Model',
    
    
        config: {
            idProperty: 'id',
            fields: [
                'id',
                'name'
            ],
    
    
            associations: {
                type: 'hasOne',
                model: 'ModelB'
            }
        }
    });
    
    Ext.define('ModelB', {
        extend: 'Ext.data.Model',
    
    
        config: {
            fields: [
                'category',
                'name',
                'type'
            ],
    
    
            proxy: {
                type: 'ajax',
                actionMethods: { read: 'GET' },
                withCredentials: true,
                noCache: false,
                pageParam: null,
                limitParam: null,
                startParam: null,
                url: 'url',
                reader: {
                    type: 'json'
                }
            }
        }
    });
    To load model B I executed this:

    Code:
    modelA.getModelB({
      params: {...},
      callback: function(modelB, op) { /* is called with the correct params */},
      success: function(modelB, op) { /* is called with an "array" containing the desired params */ }
    })

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,650
    Vote Rating
    899
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


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

  3. #3
    Sencha User
    Join Date
    Dec 2012
    Location
    Hamburg, Germany
    Posts
    11
    Vote Rating
    0
    emste is on a distinguished road

      0  

    Default


    One more thing I found out: If the model is already cached (and reload is not set to true), the first parameter is set correctly to the model. Obviously, there is no second parameter in this case as there has been no operation.

    This is how I work around this issue:

    Code:
    success: function(model, operation) {
        if(undefined === operation && 2 === model.length) {
            operation = model[1];
            model = model[0];
        }
    }
    Mind that you can't rely on the existence of the operation parameter!

Thread Participants: 1