30 May 2012 1:02 PM #1
Add/Remove Models from store without causing update/delete?
Hi, I have a tab panel with two tabs in it. Each tab has a grid, and each grid is driven by a JSONStore. One tab is for "pending" items and the other is for "processed" items.
When someone marks a pending item as done, I'd like to remove it from the pending store and add it to the processed store after it is saved. However, I don't want this to cause a delete or attempt an insert when either store is synced. Assuming this makes sense and what I'm trying to do is obvious, is there a way to make this happen? Or perhaps an alternate approach that sidesteps the issue?
15 Apr 2013 3:54 AM #2
Set the record's phantom variable to true. When you remove the item from the store the store will think that the item is not persisted to database and will not try to delete it using the store/model proxy.
record.phantom = true; store.remove(record);
When Alice deletes item X, a signal is sent to Bob and X should be removed from Bob's list. Doing remove() on the store for the list will fire another delete to the server which will fail with "X does not exist".
15 Apr 2013 5:22 AM #3
I believe you can also set autoSync to false (so it does not attempt to sync automatically), then just remove it and call commitChanges().
15 Apr 2013 5:26 AM #4
But then it will do the delete on the proxy when you do sync() on the store the next time later. Right? That would be bad in our use cases.
15 Apr 2013 5:35 AM #5
No, commitChanges basically tells the store to accept the pending changes (added, updated, or deleted records). Normally this is called at the end of a successful sync automatically, so you're just bypassing the sync and forcing it to accept the pending changes.
15 Apr 2013 5:51 AM #6
One could also temporarily suspend autosync?
Last edited by Drömbolaget; 16 Jul 2013 at 3:23 AM. Reason: alternative solution