delian
9 Oct 2014, 10:43 AM
autoSync property of a store set to true is quite useful and popular feature. It automates CRUD operations trough your proxy, so if you add/insert/set/delete records to a store you don't have to write you own code for the REST operations.
However, I found a bug with the latest ExtJS 5.0.1 -
If you create a data model and you have idProperty set within, then Create and Delete do not work anymore. While Update and Read are still operational as before.
This is quite a serious problem. If you use the very popularo MongoDB as a backend, you most probably use '_id' as ID property name instead of the default 'id'.
I use the following code to test the problem (check the comments in the code, written in red):
Ext.define('MyModel', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.field.Field'
],
idProperty: 'username', // If this line is removed, everything works fine
fields: [
{ name: 'username' },
{ name: 'xxx' }
]
});
Ext.define('MyStore', {
extend: 'Ext.data.Store',
requires: [
'MyModel',
'Ext.data.proxy.Rest'
],
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'MyStore',
autoLoad: true,
autoSync: true,
model: 'MyModel',
proxy: {
type: 'rest',
url: '/rest/service',
reader: {
type: 'json',
rootProperty: 'rows'
}
}
}, cfg)]);
}
});
s = Ext.create('MyStore');
s.insert(0,{ username: 'xxxx' }); // This is supposed to fire add event and to do REST POST operation. Doesn't work if idProperty is set! Works if idProperty is removed
s.getAt(0).set('username','yyyy'); // This is supposed to do REST PUT, works with or without idProperty set
s.remove(s.getAt(0)); // This is supposed to do REST DELETE, Doesn't work if idProperty is set! Works if idProperty is removed!
If idProperty is set in the Model, then insert and remove does not fire autoSync events for add and remove. Update still works fine. This is quite confusing and do not allow a lot of programs developped with earlier versions of ExtJS and MongoDB (not only them) to be migrated to ExtJS 5.
However, I found a bug with the latest ExtJS 5.0.1 -
If you create a data model and you have idProperty set within, then Create and Delete do not work anymore. While Update and Read are still operational as before.
This is quite a serious problem. If you use the very popularo MongoDB as a backend, you most probably use '_id' as ID property name instead of the default 'id'.
I use the following code to test the problem (check the comments in the code, written in red):
Ext.define('MyModel', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.field.Field'
],
idProperty: 'username', // If this line is removed, everything works fine
fields: [
{ name: 'username' },
{ name: 'xxx' }
]
});
Ext.define('MyStore', {
extend: 'Ext.data.Store',
requires: [
'MyModel',
'Ext.data.proxy.Rest'
],
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'MyStore',
autoLoad: true,
autoSync: true,
model: 'MyModel',
proxy: {
type: 'rest',
url: '/rest/service',
reader: {
type: 'json',
rootProperty: 'rows'
}
}
}, cfg)]);
}
});
s = Ext.create('MyStore');
s.insert(0,{ username: 'xxxx' }); // This is supposed to fire add event and to do REST POST operation. Doesn't work if idProperty is set! Works if idProperty is removed
s.getAt(0).set('username','yyyy'); // This is supposed to do REST PUT, works with or without idProperty set
s.remove(s.getAt(0)); // This is supposed to do REST DELETE, Doesn't work if idProperty is set! Works if idProperty is removed!
If idProperty is set in the Model, then insert and remove does not fire autoSync events for add and remove. Update still works fine. This is quite confusing and do not allow a lot of programs developped with earlier versions of ExtJS and MongoDB (not only them) to be migrated to ExtJS 5.