X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/7a654f8d43fdb43d78b63d90528bed6e86b608cc..6746dc89c47ed01b165cc1152533605f97eb8e8d:/docs/source/BelongsToAssociation.html diff --git a/docs/source/BelongsToAssociation.html b/docs/source/BelongsToAssociation.html index a522a786..2849fa95 100644 --- a/docs/source/BelongsToAssociation.html +++ b/docs/source/BelongsToAssociation.html @@ -1,4 +1,21 @@ -
/**
+
+
+
+
+ The source code
+
+
+
+
+
+
+ /**
* @author Ed Spencer
* @class Ext.data.BelongsToAssociation
* @extends Ext.data.Association
@@ -120,7 +137,7 @@ Ext.define('Ext.data.BelongsToAssociation', {
alias: 'association.belongsto',
- /**
+ /**
* @cfg {String} foreignKey The name of the foreign key on the owner model that links it to the associated
* model. Defaults to the lowercased name of the associated model plus "_id", e.g. an association with a
* model called Product would set up a product_id foreign key.
@@ -146,17 +163,17 @@ product.getOrder(); // Will make a call to the server asking for order_id 22
* </code></pre>
*/
- /**
+ /**
* @cfg {String} getterName The name of the getter function that will be added to the local model's prototype.
* Defaults to 'get' + the name of the foreign model, e.g. getCategory
*/
- /**
+ /**
* @cfg {String} setterName The name of the setter function that will be added to the local model's prototype.
* Defaults to 'set' + the name of the foreign model, e.g. setCategory
*/
- /**
+ /**
* @cfg {String} type The type configuration can be used when creating associations using a configuration object.
* Use 'belongsTo' to create a HasManyAssocation
* <pre><code>
@@ -187,7 +204,7 @@ associations: [{
ownerProto[setterName] = me.createSetter();
},
- /**
+ /**
* @private
* Returns a setter function to be placed on the owner model's prototype
* @return {Function} The setter function
@@ -216,7 +233,7 @@ associations: [{
};
},
- /**
+ /**
* @private
* Returns a getter function to be placed on the owner model's prototype. We cache the loaded instance
* the first time it is loaded so that subsequent calls to the getter always receive the same reference.
@@ -235,45 +252,44 @@ associations: [{
return function(options, scope) {
options = options || {};
- var foreignKeyId = this.get(foreignKey),
- instance, callbackFn;
+ var model = this,
+ foreignKeyId = model.get(foreignKey),
+ instance,
+ args;
- if (this[instanceName] === undefined) {
+ if (model[instanceName] === undefined) {
instance = Ext.ModelManager.create({}, associatedName);
instance.set(primaryKey, foreignKeyId);
if (typeof options == 'function') {
options = {
callback: options,
- scope: scope || this
+ scope: scope || model
};
}
associatedModel.load(foreignKeyId, options);
+ model[instanceName] = associatedModel;
+ return associatedModel;
} else {
- instance = this[instanceName];
-
+ 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.
- if (typeof options == 'function') {
- options.call(scope || this, instance);
- }
-
- if (options.success) {
- options.success.call(scope || this, instance);
- }
-
- if (options.callback) {
- options.callback.call(scope || this, instance);
- }
+ 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;
}
};
},
- /**
+ /**
* Read associated data
* @private
* @param {Ext.data.Model} record The record we're writing to
@@ -284,4 +300,6 @@ associations: [{
record[this.instanceName] = reader.read([associationData]).records[0];
}
});
-
\ No newline at end of file
+
+
+