model associations not filled with data
Hi
I've followed the example defined here, but whatever I try I cannot get the associations to contain any data.
So, here are my stores and two models
Code:
Ext.define("ModelTest.store.Data", {
extend: "Ext.data.Store",
config: {
storeId: "usersStore",
data : [
{ id: 1, firstName: "Ed Spencer",
products: [{id: 1, name: 'THis is a comment', user_id: 1 }]
}], ],
model: "ModelTest.model.User",
autoLoad: true,
}
});
The User model
Code:
Ext.define('ModelTest.model.User', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'id', type: 'int'},
{name: 'name', type: 'string'}
],
hasMany: {model: 'Product', name: 'products'}
}
});
and finally the Product model
Code:
Ext.define('ModelTest.model.Product', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'id', type: 'int'},
{name: 'user_id', type: 'int'},
{name: 'name', type: 'string'}
]
}
});
Then, from the console I did
Code:
Ext.getStore('usersStore').getData().each(function(i) {
console.dir(i.products());
})
which returns 'products is not defined'. Any suggestions why the association is empty ?
Cheers