PDA

View Full Version : Record model does not correspond with Store model



1099511627776
3 May 2012, 9:51 AM
Hello, I'm stuck with this kind of problem:
I have a parent store with 2 descendant stores and corresponding models:
Parent Store


Ext.define('ASV.metaobjects.store.document',{
extend: 'Ext.data.Store',
autoLoad:false,
api:{..........}
}
});

Desceendant stores


Ext.define('ASV.store.document.order',{
extend: 'ASV.metaobjects.store.document',
doctype:'orders',
model:'ASV.model.document.order'
});

Ext.define('ASV.store.document.ooutrder',{
extend: 'ASV.metaobjects.store.document',
doctype:'orders1',
model:'ASV.model.document.outorder'
});

As you can see theese stores have different models (order and outorder)
Now when I load store with model "outorder" I get a store with records that have model "order"34845

Where can be an error?

vietits
3 May 2012, 5:45 PM
1. How do you populate data to store? What is your data before loading to store?
2. I have tried your code with the following example and everything works well.


Ext.onReady(function(){
Ext.define('ASV.model.document.order', {
extend: 'Ext.data.Model',
fields: ['f1','f2']
});


Ext.define('ASV.model.document.outorder', {
extend: 'Ext.data.Model',
fields: ['a1','a2']
});


Ext.define('ASV.metaobjects.store.document',{
extend: 'Ext.data.Store',
autoLoad:false
});


Ext.define('ASV.store.document.order',{
extend: 'ASV.metaobjects.store.document',
doctype:'orders',
model:'ASV.model.document.order'
});


Ext.define('ASV.store.document.ooutrder',{
extend: 'ASV.metaobjects.store.document',
doctype:'orders1',
model:'ASV.model.document.outorder'
});


var store1 = Ext.create('ASV.store.document.order', {
data: [{
f1:1,f2:2
}]
});
var store2 = Ext.create('ASV.store.document.ooutrder', {
data: [{
a1:1,a2:2
}]
});
console.log(store1, store2, store2.getAt(0))
});

1099511627776
4 May 2012, 12:33 AM
I think? i've got it.
in parent store i've defined a proxy. Then, when i've created a first descendant, it populated it's model 'order' to proxy, then when creating second descendand with other model was already populated with first model.
The Solution was to make proxy confiig not in definition but in onstructor function:
before:



Ext.define('ASV.metaobjects.store.document',{ extend: 'Ext.data.Store', autoLoad:false, api:{..........} },
proxy:{....
} });

After:



Ext.define('ASV.metaobjects.store.document',{ extend: 'Ext.data.Store', autoLoad:false, api:{..........} },
constructor:function(config){
var proxy = {........};
config['proxy'] = proxy;
this.callParent([config]);
} });