This took me much time to find. The problem is due to the way Extjs determines when a record needs to be synched: the phantom
property.
To add a new record to a store, you must not give the id
. This will not work (since the id is set, the record will not be marked as phantom
, and it will not get synched) :
store.add({id: 1, name: 'new'})
store.sync()
This will work:
store.add({name: 'new'})
store.sync()
There is also a possible workaround, by setting the phantom
property after adding the records. This can be necessary when the id
has some meaning and is more than just an autoincremented value :
Ext.Array.each(store.add({id: 1, name: 'new'}), function(record){
record.phantom = true
});
store.sync()
An allusion to the problem is made at Extjs.data.Model.phantom
: Any record which has a real database pk set as its id property is NOT a phantom -- it's real.
It's clear that this statement is not necessarily true, like above in the first code snippet, but since Extjs 4.2 assumes it to be true always, the bug appears.
I hope that this explanation will save somebody some hours of work. It would have saved me a day.