Hybrid View
-
19 Apr 2012 11:43 AM #1
Ext 4.1 RC3 HasOne Assocation Bug
Ext 4.1 RC3 HasOne Assocation Bug
Ext version tested:
- Ext 4.1 rev RC3
- 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.
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; } }; } });
-
20 Apr 2012 8:32 AM #2
Thank you for the report!
Regards,
Scott.
-
3 Jul 2012 1:15 AM #3
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.
Question: Should I open a new bug for this?Code:instance = Ext.ModelManager.create({}, associatedName); // This is deprecated BTW
-
3 Jul 2012 7:37 AM #4
If you feel you have a valid case that is a separate issue, please create a new report.
Regards,
Scott.
Success! Looks like we've fixed this one. According to our records the fix was applied for
EXTJSIV-5993
in
4.1.


Reply With Quote