I've ready many posts about this problem. I've never seen an answer that actually worked. Here is what is going on (at least in Ext 4.1)
in Ext.data.Model
Code:
associationsMixedCollection = new Ext.util.MixedCollection(false, prototype.itemNameFn),
which means that Ext.data.Model.itemNameFn will be used in Ext.util.AbstractMixedCollection.add if no key argument is used. Model.itemNameFn is
Code:
itemNameFn: function(item) {
return item.name;
}
so in Ext.data.Model, the line
Code:
associationsMixedCollection.add(Ext.data.association.Association.create(associationConfig));
causes the created association's name property to be used as the key. If you do not explicitly set the name property in the association config, then it will be the model's name. So multiple associations to the same model over write each other in the associationsMixedCollection
Here is a model config that actually works with multiple associations to the same model
Code:
hasOne: [
{
instanceName: 'billTo',
name: 'billTo',
associationKey: 'billTo',
model: 'CrmApp.model.Contact',
getterName: 'getBillTo',
foreignKey: 'billToId',
setterName: 'setBillTo'
},
{
instanceName: 'shipTo',
name: 'shipTo',
associationKey: 'shipTo',
model: 'CrmApp.model.Contact',
getterName: 'getShipTo',
foreignKey: 'shipToId',
setterName: 'setShipTo'
}
]