1. #1
    Sencha User tf.alves's Avatar
    Join Date
    Feb 2010
    Location
    Portugal
    Posts
    54
    Answers
    3
    Vote Rating
    0
    tf.alves is on a distinguished road

      0  

    Default Unanswered: Store not syncing properly

    Unanswered: Store not syncing properly


    Hi,

    I want to "refresh" a store in order to fetch new items from the proxy. The problem is that whenever I call the sync() method, it doesn't make a request to the server. The problem goes away if I remove the 'id' field from my store's model's fields.

    Why is this happening? I want to reload my store with new Items, but If they have Id's it will not sync. If I don't have Id's it will duplicate items...

    Please Help!

    The store:
    Code:
    App.stores.agenda_store = new Ext.data.Store({    model: 'AgendaItem',
        sorters: 'data',
        proxy: {
            type: 'ajax',
            url: './app/requests/agenda/agenda.php',
            reader: {
                type: 'json',
                root: 'items'
            }
        }    
    });
    The model:
    Code:
    Ext.regModel('AgendaItem', {    fields: [
            {name: 'id', type:'int'},
            {name: 'disciplina', type: 'string'},
            {name: 'trabalho',   type: 'string'},
            {name: 'data', type: 'date', dateFormat: 'Y-m-d'},
            {name: 'hora', type: 'date', convert: hourParser}
        ]
    });
    The list:
    Code:
    this.list = new Ext.List({            scroll:'vertical',
                fullscreen:true,
                itemCls: 'evento-item',
                itemTpl :'<table class="evento"><tr><td><h1>{disciplina}</h1>{trabalho:ellipsis(60)}</td><th>{data:date("d/m/Y")}<br/>{hora}</th></tr></table>',
                store: App.stores.agenda_store
    });

  2. #2
    Sencha User tobiu's Avatar
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,680
    Answers
    130
    Vote Rating
    112
    tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all

      0  

    Default


    please provide a short code example!
    Best regards
    Tobias Uhlig
    __________

    S-CIRCLES Social Network Engine

  3. #3
    Sencha User tf.alves's Avatar
    Join Date
    Feb 2010
    Location
    Portugal
    Posts
    54
    Answers
    3
    Vote Rating
    0
    tf.alves is on a distinguished road

      0  

    Default


    You're right, I updated the first post with the code.

  4. #4
    Sencha User alok.sharma127's Avatar
    Join Date
    Jun 2012
    Posts
    14
    Answers
    1
    Vote Rating
    1
    alok.sharma127 is on a distinguished road

      0  

    Default


    Hey,

    I'm facing a similar problem, though I'm not able to get my store to sync even if I remove the id field from my store's model.
    Were you able to fix this issue? If so, how?

    Thanks.

  5. #5
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,092
    Answers
    112
    Vote Rating
    95
    Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light

      0  

    Default


    Are you trying to load new entries from the server or saving newly added entries in the store to the server? in the former case, you have to call store.load(). store.sync() only works when there are any changes in the records in the store.

  6. #6
    Sencha User alok.sharma127's Avatar
    Join Date
    Jun 2012
    Posts
    14
    Answers
    1
    Vote Rating
    1
    alok.sharma127 is on a distinguished road

      0  

    Default


    Thanks for your quick reply Farish.

    I'm trying to load data from local storage to a store. This store has a Rest proxy. So basically calling store.sync() on this store shouldve executed the rest call, but unfortunately the sync() call is never executed.

  7. #7
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,092
    Answers
    112
    Vote Rating
    95
    Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light

      1  

    Default


    before calling store.sync(), do the following:

    Code:
    console.log(store.getNewRecords());
    console.log(store.getUpdatedRecords());
    console.log(store.getRemovedRecords());
    and look at the output in Firebug console. If the result is empty of all three, the store has nothing to sync i.e. there is no new, updated or deleted record in the store.

    To test more, you can change one records:

    Code:
    store.getAt(0).set({field: value});
    This will change the value of the field you specify for the first record in the store. Now if you call store.sync(), it should send a request.

  8. #8
    Sencha User alok.sharma127's Avatar
    Join Date
    Jun 2012
    Posts
    14
    Answers
    1
    Vote Rating
    1
    alok.sharma127 is on a distinguished road

      0  

    Default


    Sorry for the delay.
    Surprisingly, all 3 of those console commands gave me an empty array. I really have no clue why this would happen. Do you have any ideas?

    Some code:

    Code:
    var offlineStore1 = Ext.create('xyzs.store.offlineStore');
                  var onlineStore1 = Ext.create('xyzs.store.upStore');
                  
                  var up_Model = Ext.create('mUserStories.model.upPersonModel',{
                       datafield1 = formfield1;   
                  });
    
                 offlineStore1.add(up_Model); offlineStore1.sync();
    
    //Now in some other function, I copy data from this offline store to an Online store(the one with the rest call).
    
                offlineStore1.each(function(record){
                         onlineStore1.add(record);
                         onlineStore.sync(); //This is never called.
                });
    So I added the 3 console logs in between onlineStore1.add and onlineStore.sync() and it seems there's nothing to be synced.

  9. #9
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,092
    Answers
    112
    Vote Rating
    95
    Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light

      0  

    Default


    before calling store.add(), try setting the dirty flag of the record to true. record.dirty = true; and then add it to the store. See what happens then. Also, you should call sync outside the loop so that its called only once after all records have been added. For new records, record.phantom is true and for updated records, record.dirty is true. if both these are false for all records, the store thinks all records are 'stable'. May be copying the records this way doesnt cause the dirty or phantom configs to be true...

  10. #10
    Sencha User alok.sharma127's Avatar
    Join Date
    Jun 2012
    Posts
    14
    Answers
    1
    Vote Rating
    1
    alok.sharma127 is on a distinguished road

      0  

    Default


    On setting record.dirty, my store executes a PUT instead of a POST. Unfortunately, I'm not authorized to execute a PUT on the server I'm working with, and I must only do a POST.
    I noticed this time the getUpdatedRecords console log was not empty, however getNewRecords was empty. So if somehow I can indicate this newly added record as a fresh record, a POST will be executed (?)

    Also, I need to have sync() called individually on the store elements since there are subsequent POST requests executed once a data is synced. I intend to do this by listening to store.on('sync).