PDA

View Full Version : store.sync() called twice causes duplicate insert



JoepRonde
29 Jan 2014, 1:08 AM
In our ExtJS 4.1 application we call store.sync() twice.
The second sync() getNewRecords() includes also the getNewRecords() that were included in the first sync(). Causing inserting twice in the database and a duplicate key error.

Is this normal behaviour or maybe a bug in ExtJS?
How can we best cope with this issue?

We now have a workaround by check on existance of a record just before the database insert. But it would be better to avoid the duplicate insert.

this is the statement that is done twice shortly after one order:
me.userWidgetOptions.sync();
Thanks in advance for any help!

f.baron
29 Jan 2014, 1:30 AM
Hi!

You could use 'store.commitChanges()' after sync.

JoepRonde
31 Jan 2014, 5:11 AM
store.commitChanges() solves the duplicate inserts, but introduces another problem. It also makes phantom= true for the client records which causes that the records of the respone are not copied to the client records. Because of this the id of the inserted record (that is generated by the server) is not known on the client store. So an update of a previous created record fails.