1

I call a belongsTo assocation generated getter function:

        token.getUser({
            callback: function(user, operation) {
                console.info('getUser callback');
                Ext.Viewport.unmask();
                console.dir(operation);
            },
            failure: function(user, operation) {
                console.info('getUser failure');
            },
            success: function(user) {
                console.info('getUser success');
            }
        });

My console shows the following:

getUser success Auth.js:74
getUser failure Auth.js:69
getUser callback Auth.js:64
undefined

Can someone please enlighten me how this works? The docs doesn't help much.

Tjorriemorrie
  • 16,818
  • 20
  • 89
  • 131

1 Answers1

2

Most certainly a bug. Look at the code of the createGetter method:

        if (options.reload === true || instance === undefined) {
            ...
        } else {
            args = [instance];
            scope = scope || model;

            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;
        }

If the associated model has already been loaded, all callbacks are called indiscriminately.

You can use the following workaround, as we see that the second argument is not called for cached instances:

token.getUser({
    callback: function(user, operation) {

        // independent of success

        if (operation) {
            if (operation.wasSuccessful()) {
                // successful load
            } else {
                // failed load
            }
        } else {
            // retrieved from the cache (indicates previous success)
        }
    }
});
rixo
  • 23,815
  • 4
  • 63
  • 68