4th version seems to have many very promising features and new Association class is not least among them. But as almost everything it does not work. Samples from guides raises lot of vague error messages and stop application working. Looks like the architector of the library changed his mind few times and the coders did not understood his ideas either.
For beginning the only Association class play two different roles: a wrapper for compound objects read from proxies and a tool to handle relation databases. It is not bad idea but implementation is terrible. The same API interpreters the same parameters in very different ways in returns absolutely different results.
Just take a look at this:

The next problem is the comrades messed up Ext.loader ability to look for classes by names with simple class managers which require exact full path.
But hands on. Let it be a data like this:
[{
id: 1,
site: 'www.armour.up',
component: {
id: 2,
name: 'theme'}
},{
id: 3,
site: 'www.armour.up',
component_id: 4
component: {
id: 4,
name: 'plugins'
}
}]
I.e. two instances on site description which contain component description objects inside them. The model to handle this stream as whole is:
Ext.define('D.model.Deploy', {
extend: 'Ext.data.Model',
alias: 'model.deploy',
fields:[{
name:'id', type: 'int'},{
name:'site', type: 'string'},{
}],
associations: [{
type: 'belongsTo',
model: 'D.model.Component',
associatedName: 'Component',
instanceName: 'component'
}],
The magic is to give associations options right values.
model must be full path to a model class of bound object – it will be used to create instances;
associatedName – this is base for generating bunch of names:
name : associatedName,
foreignKey : associatedName.toLowerCase() + "_id",
instanceName: associatedName + 'BelongsToInstance',
associationKey: associatedName.toLowerCase()
getterName = me.getterName || 'get' + associatedName,
setterName = me.setterName || 'set' + associatedName;
I do not like default value of instanceName – the name of the model field which will hold child model and change it explicitly.
There’s nothing special besides that. The instances of Deploy models will have instances of D.model.Component accessible either by property .component(record.ComponentBelongsToInstance) or with method record.getComponent().
But everything change if proxy provides typical relation database data:
[{
id: 1,
site: 'www.armour.up',
component_id: 2
},{
id: 3,
site: 'www.armour.up',
component_id: 4
}]
Association model become more verbose:
associations: [{
type: 'belongsTo',
model: 'D.model.Component',
associatedName: 'D.model.Component',
getterName: 'getComponent',
name: 'component',
foreignKey: 'component_id',
instanceName: 'component'
}]
The troubles caused by one small piece of code where associatedName used to create model instance. Because of that it must be full name. Needless to say the dotted name can not be used anymore as base for the others. The getter name for example turns into getD.model.Component. Beside necessity of naming all parameters the foreignKey must be added as well.
The change in associations description is not all. A function getComponent behaves absolutely diffrently. It becomes void but accepts pretty fancy parameter built from couple functions - one will be called on success of pulling data for inner model and the other in case of failure:
record.getComponent({
success:function(a,b){console.log(a);console.log(b)}
failure:function(a,b){console.log(a);console.log(b)}
});