PDA

View Full Version : Can't have more than one association instance of the same model



stephenr85
3 Oct 2012, 12:29 PM
Architect doesn't expose the associatedName config for associations, which causes the cached property to be "{ModelName}BelongsToInstance", creating a conflict when you want to association multiple models of the same type.

For now, I've overcome this by overriding the getInstanceName methods of the associations to use the associationKey, if it's available, i.e.:


Ext.define('Ext.data.association.override.BelongsTo', {
override: 'Ext.data.association.BelongsTo',
getInstanceName:function(){
var assKey = this.getAssociationKey();
return assKey ? assKey+'BelongsToInstance' : me.callParent();
}
});

dmulcahey
7 Oct 2012, 5:50 AM
There is a property called instanceName for hasOne associations. It isn't exposed by default in SA but if you type it in to the search area for configs like this: instanceName:'someInstanceName' and click add SA will add it for you as a custom property. If you give each instance of a hasOne association a seperate instanceName it should let you have multiple hasOne associations to the same model.

stephenr85
10 Oct 2012, 6:19 AM
Thanks for the tip! I must admit my eyes have skipped over that field for a while now. From looking at the code/docs, I think associatedName is the intended config variable for this, or possibly the fallback (instanceName isn't mentioned in the docs). I think this is still a low-priority bug for Architect, which should expose a config variable to prevent overlapping the "cache" keys.