PDA

View Full Version : Help with associeted model and Data



Syndicate
3 Jun 2015, 10:27 PM
I cant get associated data from the store.
What I'm doing wrong?



Ext.define('Books', {
extend: 'Ext.data.Model',

requires: 'MyApp.model.Files',

fields: ['title'],

hasMany: {
model: 'Files',
name: 'files',
associationKey: 'files'
},
});

Ext.define('Files', {
extend: 'Ext.data.Model',
fields: ['title']
});

Ext.define('MyApp.store.Books', {
extend: 'Ext.data.Store',
requires: 'MyApp.model.Books',

model: 'Books',

autoLoad: true,

data: [
{
title: 1,
files: [
{
title: 1
}
]
},
{
title: 2,
files: [
{
title: 2
}
]
}
]

});


Ext.create('MyApp.store.Books').first().getData(true) // files.length === 0 ?!

joel.watson
4 Jun 2015, 6:38 AM
Hi--

To get this to work with inline data on the store, you'll need to establish a memory proxy on the store so that the data can be processed through the reader at which time the associations will be constructed and reconciled. Here's an example with a slightly modified version of your code:

https://fiddle.sencha.com/#fiddle/o25

I hope that helps!
Thanks
Joel

Syndicate
5 Jun 2015, 12:32 AM
Hi. Thanks for help! So simple :)

joel.watson
5 Jun 2015, 6:25 AM
Hi. Thanks for help! So simple :)

Cool, glad it was helpful!

Thanks!
Joel