Hello,
I'm trying to use the generated association functions as described in the data guide to traverse associations in my model. For instance, a workspace has many portlets. When I define these two models and a store, and then I try to use workspace.portlets() I don't get any of the portlets. But if I walk the data field I see the data. Please see my example below and the console.log statements.
Code:
Ext.define('Workspace', {
extend: 'Ext.data.Model',
fields: [
'id','name'
],
hasMany : {model:'Portlet', name:'portlets'}
});
Ext.define('Portlet', {
extend: 'Ext.data.Model',
fields: [
'id', 'workspace_id', 'name', 'column'
],
belongsTo : 'Workspace'
});
Ext.onReady(function() {
var portletStore = new Ext.data.Store({
storeId: 'portletStore',
model: 'Workspace',
data: [
{
"id":1,
"name": 'hello workspace',
"portlets": [
{
"id":1
,"workspace_id":1
,"title": "One"
,"column": 1
,"xtype": "chartportlet"
}
,
{
"id":2
,"workspace_id":1
,"title": "Two"
,"column" : 2
,"xtype": "gridportlet"
}
]
}
]
});
console.log(portletStore.first());//Works and data property shows two child portlets
console.log(portletStore.first().portlets());//Does not contain any child portlets
console.log(portletStore.first().data.portlets);//Does contain child portlets
console.log(portletStore.first().getAssociatedData());//empty
});
I must be building the relationship wrong but I can't see why. Any help would be appreciated.