Success! Looks like we've fixed this one. According to our records the fix was applied for EXTJS-5993 in a recent build.
  1. #1
    Sencha User ykey's Avatar
    Join Date
    Mar 2010
    Location
    USA
    Posts
    245
    Vote Rating
    27
    ykey has a spectacular aura about ykey has a spectacular aura about

      0  

    Default Ext 4.1 RC3 HasOne Assocation Bug

    Ext 4.1 RC3 HasOne Assocation Bug


    Ext version tested:
    • Ext 4.1 rev RC3
    Description:
    • Maybe I am crazy but I think the generated getter success callback is using Function.call when it should be using Function.apply. Also the scope is not used on the second call to the generated getter if the scope provided in the options config.
    Fix
    Code:
    Ext.define(App.override.data.association.HasOne', {
        override: 'Ext.data.association.HasOne',
    
    
        createGetter: function() {
            var me              = this,
                ownerModel      = me.ownerModel,
                associatedName  = me.associatedName,
                associatedModel = me.associatedModel,           
                foreignKey      = me.foreignKey,
                primaryKey      = me.primaryKey,
                instanceName    = me.instanceName;
    
    
            return function(options, scope) {
                options = options || {};
    
    
                var model = this,
                    foreignKeyId = model.get(foreignKey),
                    scope = options.scope || scope,
                    success,
                    instance,
                    args;
    
    
                if (options.reload === true || model[instanceName] === undefined) {
                    instance = Ext.ModelManager.create({}, associatedName);
                    instance.set(primaryKey, foreignKeyId);
    
    
                    if (typeof options == 'function') {
                        options = {
                            callback: options,
                            scope: scope || model
                        };
                    }
    
    
                    // Overwrite the success handler so we can assign the current instance
                    success = options.success;
                    options.success = function(rec){
                        model[instanceName] = rec;
                        if (success) {
                            success.apply(this, arguments);
                        }
                    };
    
    
                    associatedModel.load(foreignKeyId, options);
                    // assign temporarily while we wait for data to return
                    model[instanceName] = instance;
                    return instance;
                } else {
                    instance = model[instanceName];
                    args = [instance];
                    scope = scope || model;
    
    
                    //TODO: We're duplicating the callback invokation code that the instance.load() call above
                    //makes here - ought to be able to normalize this - perhaps by caching at the Model.load layer
                    //instead of the association layer.
                    Ext.callback(options, scope, args);
                    Ext.callback(options.success, scope, args);
                    Ext.callback(options.failure, scope, args);
                    Ext.callback(options.callback, scope, args);
    
    
                    return instance;
                }
            };
        }
    });

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,999
    Vote Rating
    456
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Thank you for the report!

    Regards,
    Scott.

  3. #3
    Sencha User
    Join Date
    Sep 2010
    Posts
    51
    Vote Rating
    2
    ExTriqui is on a distinguished road

      0  

    Default associatedName

    associatedName


    I would like to add that the use of associatedName is worng in some parts of the code.
    Maybe it's me who is wrong but if you use a model name like 'App.model.Customer' and want to use it with associations you can either specify associatedName: 'Customer' to have getterName = getCustomer, setterName = setCustomer, associationKey = customer, foreignKey = customer_id and instanceName = CustomerBelongsToInstance (for example) or you can specify all of them.
    The problem is that the first approach doesn't work since associatedName is used in same places where associatedModel should be used, and breaks everything, so you always need to go the second route.
    Code:
    instance = Ext.ModelManager.create({}, associatedName); // This is deprecated BTW
    Question: Should I open a new bug for this?

  4. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,999
    Vote Rating
    456
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    If you feel you have a valid case that is a separate issue, please create a new report.

    Regards,
    Scott.

Thread Participants: 2