PDA

View Full Version : Namespaced model associations



abcdef
5 Dec 2011, 6:46 PM
I have 2 models as follows:



Ext.define('MyApp.model.Book', {
extend: 'Ext.data.Model',
fields: [
...
],
hasMany: {
model: 'MyApp.model.Page', name: 'pages'
}
});


Ext.define('MyApp.model.Page', {
extend: 'Ext.data.Model',
fields: [
...
],
belongsTo: 'MyApp.model.Book'
});



After I load the Book store:




listeners: {
load: function(store, records, success, operation) {
if(success) {
store.each(function(book) {
console.log(book.pages());
});
}
}
}



It throws an error:




TypeError: 'undefined' is not a function (evaluating 'book.pages()')



How do I accomplish the behavior described above with namespaced models?


Please help!


Thanks!

skirtle
5 Dec 2011, 10:11 PM
I just tried your models and I could access book.pages() fine.

Try inspecting the variable book. Perhaps it isn't what you think it is?

Have a look at MyApp.model.Book.prototype.pages, check the function exists on the prototype.

abcdef
6 Dec 2011, 1:27 AM
I just tried your models and I could access book.pages() fine.

Try inspecting the variable book. Perhaps it isn't what you think it is?

Have a look at MyApp.model.Book.prototype.pages, check the function exists on the prototype.

I'm sorry for the noise. I wasn't requiring the page model on the on the book store that had the listener.

Thanks!