PDA

View Full Version : Can't fetch associations when memory proxy used on store



kleinsch
22 Aug 2011, 11:18 AM
Sencha Touch version tested:

1.1.0


only default ext-all.css


Platform tested against:

Chrome
iOS4


Description:

When using a memory proxy on a store with a model proxied by memory, finding associations doesn't seem to work properly. If the memory proxy configuration is removed from the store, finding associations works again.


Test Case:




Ext.ns('MyApp');

MyApp.Product = Ext.regModel('Product', {
fields: [
{name: 'id', type: 'int'},
{name: 'user_id', type: 'int'},
{name: 'name', type: 'string'}
],


belongsTo: [
{model: 'User', name: 'user'}
],

proxy: {
type: 'memory',
id: 'user'
}
});


MyApp.User = Ext.regModel('User', {
fields: [
{name: 'id', type: 'int'},
{name: 'name', type: 'string'}
],


associations: [
{type: 'hasMany', model: 'Product', name: 'products'}
],

proxy: {
type: 'memory',
id: 'product'
}
});


Ext.regStore('User', {
model: "User",
data: [
{
id: 1,
name: "nick"
},
{
id: 2,
name: "jim"
}
],

// remove this section to make finding associations work again
proxy: {
type: 'memory'
}

});


Ext.regStore('Product', {
model: "Product",
data: [
{
id: 1,
user_id: 1,
name: "myProduct"
},
{
id: 2,
user_id: 1,
name: "myProduct2"
},
{
id: 3,
user_id: 2,
name: "myProduct3"
},
{
id: 4,
user_id: 2,
name: "myProduct4"
}
],


// remove this section to make finding associations work again
proxy: {
type: 'memory'
}
});


var product = Ext.getStore('Product').getById(4);
console.log('Testing finding product (should be myProduct4): ' + product.data.name);
product.getUser(function(user) {
console.log('Testing getting product\'s user via getUser (should be jim): ' + user.data.name);
});


new Ext.Application({
launch: function() {
new Ext.Panel({
fullscreen: true,
items: [
{html: 'hello world'}
]
});
}
});



Steps to reproduce the problem:

Run provided test case, examine console output


The result that was expected:

[Console output] Testing getting product's user via getUser (should be jim): jim


The result that occurs instead:

[Javascript error] Uncaught TypeError: Cannot read property 'data' of undefined
This happens because the getUser function erroneously doesn't find the user, even though it exists in the memory proxy


Debugging already done:

Removing the proxy statements from the stores in my test case fixes this problem. That solution isn't very intuitive though, so I felt like this wasn't intentional behavior.