Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha User
    Join Date
    Jun 2011
    Posts
    17
    Vote Rating
    0
    schtono is on a distinguished road

      0  

    Exclamation Store findById uses old dataset after second load()

    Store findById uses old dataset after second load()


    TLDR: findById() does not work after different dataset is loaded into store.

    Given the following situation:

    (1) Create a datastore and set an arbitrary filter upon instatiation
    (2) load() a dataset through a json-proxy
    (3) retrieve arbitrary record via store.findById() -> returns the correct record
    (4) change the url-parameters of the corresponding proxy to fetch a slightly different dataset
    (5) load() the "different" dataset
    (6) store.findById() does not return the correct record in the new dataset. Instead, it returns the corresponding record from the previous dataset.

    I investigated the issue and found that store.findById() works on either the actual dataset or a snapshot (this.data vs. this.snapshot in the source). The second load() command (see 5) probably does not correctly reset the snapshot of data.

    Best
    Philipp

  2. #2
    Sencha User
    Join Date
    Apr 2008
    Location
    Buenos Aires, Argentina
    Posts
    66
    Vote Rating
    0
    elmasse is on a distinguished road

      0  

    Default


    I have the same issue, I've just override the getById method on Store instance to not use snapshot and that fixed the problem, at least as a quick workaround.

    I think it has to do with snapshot, when filter method is called on the second load (no matter if you have added a filter or not) this.snapshot is a valid object but whit wrong data and this line makes the difference:

    Code:
    this.snapshot = this.snapshot || this.data.clone();
    So, as I said, my quick fix is to override the getById method from:
    Code:
        getById : function(id) {
            return (this.snapshot || this.data).findBy(function(record) {
                return record.getId() === id;
            });
        },
    to:

    Code:
        getById : function(id) {
            return this.data.findBy(function(record) {
                return record.getId() === id;
            });
        }

  3. #3
    Sencha User
    Join Date
    Jun 2011
    Posts
    17
    Vote Rating
    0
    schtono is on a distinguished road

      0  

    Default


    Thanks for posting the fix, I use the same solution and it works. Dirty though

  4. #4
    Sencha User
    Join Date
    Jan 2012
    Posts
    16
    Vote Rating
    0
    Travisrowland is on a distinguished road

      0  

    Default


    Oh my! I am so glad I found this, it was driving me up the freaking wall. Thanks for the fix.

  5. #5
    Sencha Premium Member findajit's Avatar
    Join Date
    Mar 2009
    Location
    Hyderabad, India
    Posts
    61
    Vote Rating
    0
    findajit is on a distinguished road

      0  

    Default


    Quote Originally Posted by schtono View Post
    TLDR: findById() does not work after different dataset is loaded into store.

    Given the following situation:

    (1) Create a datastore and set an arbitrary filter upon instatiation
    (2) load() a dataset through a json-proxy
    (3) retrieve arbitrary record via store.findById() -> returns the correct record
    (4) change the url-parameters of the corresponding proxy to fetch a slightly different dataset
    (5) load() the "different" dataset
    (6) store.findById() does not return the correct record in the new dataset. Instead, it returns the corresponding record from the previous dataset.

    I investigated the issue and found that store.findById() works on either the actual dataset or a snapshot (this.data vs. this.snapshot in the source). The second load() command (see 5) probably does not correctly reset the snapshot of data.

    Best
    Philipp

    Please paste an example code to reproduce this problem!
    My Book on Sencha Touch - Sencha Touch Cookbook (2nd Edition)
    My older book on Sencha Touch - Sencha Touch Cookbook
    My Sencha Touch Blog - Walking Tree Sencha Touch Blog
    My ExtJS Blog - Walking Tree ExtJS Blog
    Active contributor to - Walking Tree's ExtJS and Touch Forums

    Buy ExtJS Components from - Walking Tree e-Store

  6. #6
    Sencha User
    Join Date
    Jan 2012
    Posts
    16
    Vote Rating
    0
    Travisrowland is on a distinguished road

      0  

    Default


    I posted a way to reproduce the issue here: http://www.sencha.com/forum/showthre...a-in-formPanel

  7. #7
    Sencha User
    Join Date
    Mar 2012
    Posts
    104
    Vote Rating
    0
    izak18 is on a distinguished road

      0  

    Default


    Hi everybody, I have the same problem when I use

    Code:
    var listaDetDoc = new Ext.List({
    	id: 'listaDetDoc',
    	store: detalleMaterialStore,
    	itemTpl:
    	'<div>
                '<span class="list-izq">{Posicion} - {CodMaterialCorto}</span>'+
        '</div>',
    	listeners: {
    		'render': function (thisComponent) {
    			thisComponent.getStore().load();
    			if(detalleMaterialStore.last()){
    				var doc = listaDetDocPanel.getRecord().data.id;
    				thisComponent.getStore().filter('idDoc',doc);
    			}
    		}
    	}
    });
    How I can use your fix?
    Thanks in advance!

  8. #8
    Sencha User
    Join Date
    Jan 2012
    Posts
    16
    Vote Rating
    0
    Travisrowland is on a distinguished road

      0  

    Default


    To use the fix, you just put that getById function in your store, and it will override the default one.

  9. #9
    Sencha User
    Join Date
    Mar 2012
    Posts
    104
    Vote Rating
    0
    izak18 is on a distinguished road

      0  

    Default


    Hi Travisrowland, I did what you said, but doesn't work, I think is because the original method of this post is getById() but I'm using filter(), in my case I think will be like this:

    Code:
    var repartoStore = new Ext.data.Store ({
    	autoLoad: true,
    	model: 'repartoModel',
    	filter : function(id) {
            return this.data.findBy(function(record) {
                return record.getId() === id;
            });
        }
    });
    I'm not pretty sure what I have to do. Still not working.
    Thanks for your time.