1. #1
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Raleigh, NC
    Posts
    424
    Vote Rating
    155
    brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold

      0  

    Default Add/Remove Models from store without causing update/delete?

    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?

    Thanks,

    Brian

  2. #2
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    53
    Vote Rating
    2
    Drömbolaget is on a distinguished road

      0  

    Default


    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.

    Code:
    record.phantom = true;
    store.remove(record);
    I had a similar use case, where two user's actions are synchronized to eachother using SignalR.

    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".

  3. #3
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Raleigh, NC
    Posts
    424
    Vote Rating
    155
    brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold

      0  

    Default


    I believe you can also set autoSync to false (so it does not attempt to sync automatically), then just remove it and call commitChanges().

  4. #4
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    53
    Vote Rating
    2
    Drömbolaget is on a distinguished road

      0  

    Default


    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.

  5. #5
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Raleigh, NC
    Posts
    424
    Vote Rating
    155
    brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold brian428 is a splendid one to behold

      0  

    Default


    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.

  6. #6
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    53
    Vote Rating
    2
    Drömbolaget is on a distinguished road

      0  

    Default


    Super!

    One could also temporarily suspend autosync?

    store.suspendAutoSync();
    store.remove(record);
    store.commitChanges();
    store.resumeAutoSync();
    Last edited by Drömbolaget; 16 Jul 2013 at 3:23 AM. Reason: alternative solution

Thread Participants: 1