Results 1 to 9 of 9

Thread: How to remove a model from a data session???

  1. #1
    Sencha Premium Member
    Join Date
    Aug 2014
    Posts
    39
    Answers
    2
    Vote Rating
    4
      1  

    Default Answered: How to remove a model from a data session???

    How can I remove a model from the data session???

    I can attach it via adopt() or createRecord(). But I cannot find the counterpart. session.evict() is private and looking at the source code its implementations seem pretty incomplete (not to say it does nothing!). Using model.setSession(null) clears the model's link to the session but not the session's reference to the model.

  2. Hi,

    There is a ticket open internally for the evict functionality (which will be executed when calling drop() on a phantom record). Engineering ticket: EXTJS-12202

  3. #2
    Sencha User slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,165
    Answers
    505
    Vote Rating
    255
      0  

    Default

    Hi,

    Are you looking to only remove the record from the session and not from the server? The drop() method will set up the record to be removed from the server (along with commit) and often times is the better choice so that child / parent records are considered in the process. Though it may be good to get additional details on what your use case is.

  4. #3
    Sencha Premium Member
    Join Date
    Aug 2014
    Posts
    39
    Answers
    2
    Vote Rating
    4
      0  

    Default

    I tested various scenarios which I need in my application. None of them should require any server logic/request since the user just wants to revert the state and not commit any modifications.

    My customer store has set "session: true" and therefore uses the session from the view for all its customer models. When adding a new customer (phantom record) to the store it will automatically be attached to the store's session (regardless if I I create it via session.createRecord(...), add it via session.adopt(...) or none of the two). So far so good. Now, after the new record is created and added to the store, the user decides to remove it again since he doesn't want to save it (to the server).

    Case 1: model.drop()
    Using model.drop() the phantom record gets removed from the store. Afterwards the new customer is no longer visible in the grid and session.getChanges() returns null. Perfect. However, when calling session.visit(...) I see that the phantom customer is still referenced from the session as a "dirty" record. This looks like a memory leak to me.

    Case 2: store.rejectChanges()
    Using store.rejectChanges() the phantom record also gets removed from the store is is no longer visible in the grid. However, session.getChanges() still returns a "C"(reate)-entry for the record. Additionally, when calling session.visit(...) I see that the phantom customer is still referenced from the session as a "dirty" record as in case 1.

    Looking at your sources I can't find any other method/logic that removes a record from a session than "evict()". However, "session.evict()" is private and doesn't do anything!


    So how to deal with these problems?

  5. #4
    Sencha User slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,165
    Answers
    505
    Vote Rating
    255
      0  

    Default

    Hi,

    There is a ticket open internally for the evict functionality (which will be executed when calling drop() on a phantom record). Engineering ticket: EXTJS-12202

  6. #5
    Sencha Premium Member
    Join Date
    Aug 2014
    Posts
    39
    Answers
    2
    Vote Rating
    4
      0  

    Default

    Ah, alright! Thank you. One last question: Will this probably be fixed in 5.0.2?

  7. #6
    Sencha User slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,165
    Answers
    505
    Vote Rating
    255
      0  

    Default

    That is the plan, yes. There is an internal ticket discussing how best to implement / expose the evict functionality - whether it will be callable directly or rather via other handler methods that will check for phantom state, parent/child associations, etc before taking action with the record instance in the session.

  8. #7
    Sencha Premium Member
    Join Date
    May 2011
    Posts
    167
    Vote Rating
    12
      0  

    Default

    Could you provide a work-a-round? Just ran into this.

    i have 1 store, store.rejectChanges(), then getSession().getChanges() still returns the phantom record that was initially created...

    How do i clear the session in this case since the last store.load?

    Thanks

  9. #8
    Sencha Premium Member
    Join Date
    Aug 2014
    Posts
    39
    Answers
    2
    Vote Rating
    4
      0  

    Default

    Seems like this is not yet fixed in 5.1 beta!!!

    Dear Sencha, PLEASE FIX IT! This is enormous memory leak!

  10. #9
    Sencha User alfonso.nishikawa's Avatar
    Join Date
    Jul 2015
    Posts
    94
    Answers
    2
    Vote Rating
    27
      0  

    Default

    Any update on this? evict() is still protected.
    Asking on Ext5 but I use Ext 6.0.1. Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •