PDA

View Full Version : How to get association to play nice with MVC namespace



tonyx
28 Sep 2011, 1:38 PM
Ext.define('Category', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'int' },
{ name: 'name', type: 'string' }
]
});


Ext.define('Product', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'int' },
{ name: 'category_id', type: 'int' },
{ name: 'name', type: 'string' }
],
// we can use the belongsTo shortcut on the model to create a belongsTo association
associations: [
{ type: 'belongsTo', model: 'Category' }
]
});
var product = new Product({
id: 100,
category_id: 20,
name: 'Sneakers'
});


product.getCategory(function(category, operation) {
// do something with the category object
alert(category.get('id')); // alerts 20
}, this);



this is an example given in the documentation, which works quite nicely as expected. However, this seems to all breakdown as soon as the models are placed into their appropriate namespace. For example, if one were to prepend "App.model." to the beginning of the model names, all in a sudden the associations cease to exist. Changing the belongsTo field to reflect this change in association doesn't seem to do any good either. Any suggestions or sample code?