1. #11
    Sencha Premium Member
    Join Date
    May 2011
    Posts
    71
    Vote Rating
    6
    Answers
    5
    cyee is on a distinguished road

      0  

    Default


    Have you tried changing your 'id' field in the model to something else, like 'primaryID'?

    I believe there's a problem if you use a field called 'id' in your model

  2. #12
    Sencha User
    Join Date
    Jun 2012
    Posts
    129
    Vote Rating
    0
    Answers
    7
    munder is on a distinguished road

      0  

    Default


    Thanks, cyee. I'm using the SQLlite proxy by Shepsii, which requires an id named 'id'. I'm a bit further along now, actually. Initially, I had the following code to copy the downloaded data to the local store:
    Code:
               answersonline.each(function (record) {                            
                                 answersStore.add(record);
                            });
                            answersStore.sync();
    where 'answersonline' refers to the store containing the the downloaded data and 'answers' refers to the offline store using the SQLlite proxy. I found that my app would apparently continue before the sync was complete, with the result that it would try to display a user answer which was not actually in the store. I discovered that inserting "console.log('answer copied')" would apparently ensure that all answers were in the offline store (presumably by slowing things down). I asked in the forum if anybody knew how to detect when the sync was complete and Mitch kindly supplied an answer, which, unfortunately, was sheer gobbledegook to me. However, I took him to be saying that I should call the sync after each record was added:
    Code:
               answersonline.each(function (record) {                            
                                answersStore.add(record);
                               answersStore.sync();
                            });
    Whilst that did have the effect of ensuring that all the answers were in the table before moving on, it had the unfortunate side effect of creating multiple duplicates. I've now reverted to moving the sync outside the loop and find I now have just one of each record. (Curiously, if I downloaded 12 records, I got 12 copies of the first, 11 of the second, 10 of the third etc.) Anyway it's a relief that I now have no duplicates, BUT I still don't know how to detect when they have all been safely copied and synced to the offline store. The only relevant event I can see in the docs is beforeSync, which is the opposite of what I need. If anybody does know of an appropriate event to trap, please let me know - I'm afraid I struggle with the documentation.

  3. #13
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    24
    Vote Rating
    1
    alile is on a distinguished road

      0  

    Default


    There are two parts to this post - the first is what this chain was previously about, the second regarding what munder asked above.
    --- 1---
    I tried many things on this, and what worked for me was to only sync the stores on window unload. I added the following in Main.launch:

    Code:
    window.onbeforeunload = this.handleWindowBeforeUnload;
    and for the unload,

    Code:
    Ext.getStore("LocalNotificationStore").sync();
    Currently my solution is not duplicating any entries as it seemed that the duplication only came when saving the records. And only saving it once seems to work around that. It could well be that there are other fixes in the many that I tried that linger on in my project and they are contributing, but this was the last piece that i added which stopped the problem.

    --- 2 ---
    I recommend looping through all the records and adding them to your store, and then calling sync(). As mentioned above, each modification of a local storage record seems to cause duplication. Cannot say precisely why your approach is duping, but there it is. So your original code was better (for performance reasons as well), but what you may need to do is declare the record "dirty" for the sync to properly save it.

    Code:
    answersonline.each(function (record) 
    {                                                        
          answersStore.add(record);
          record.setDirty();
    });
    
    answersStore.sync();

  4. #14
    Sencha User
    Join Date
    Jun 2012
    Posts
    129
    Vote Rating
    0
    Answers
    7
    munder is on a distinguished road

      0  

    Default


    Thank you for you suggestion, alile. I'm afraid calling setDirty() has made no difference. It seems that sync() is not instantaneous, with the result that when the app progresses after supposedly filling the db table, the data aren't all there yet, so it coughs and splutters and falls over. I must say using (attempting to use) Sencha is a humbling experience. I've rarely felt quite so thick since being introduced to quantum mechanics in school and reading the docs is like an exercise in biblical exegesis. I recently produced in WinJS a version of the app I'm now trying to create in Sencha. A walk in the park in comparison. Good luck.

Tags for this Thread