3 Replies Latest reply on Dec 4, 2013 10:22 AM by Lars Burgess

    sync_notify, status complete yet model has zero records

    Tahir Zamir

      Hi,

       

      I am trying to process some records in a model once a "sync" has completed.

       

      In my rhodes app, in the controller.rb file, my code is basically:-

       

      def sync_notify

       

           ... status == "complete"

               

                recordCount = model.find(:all)

                model.process_records

               

       

      recordCount is always zero.  I have tried putting putting in a loop and waiting for a full minute whilst periodically checking if recordCount actually returns anything other than zero but no luck.

       

      The model does have data as I check the device for this as soon as I can once the sync is completed.  

       

      Is my approach incorrect?  Should I be trying to process the synced records at some other point in the code?

       

      Tahir

        • Re: sync_notify, status complete yet model has zero records
          Pietro Francesco Maggi

          Hi Tahir,

          model.find(:all) does not return the records count, but an array with the actual records:

          http://docs.rhomobile.com/rhodesapi/rhom-api#find

           

          if you want to know how many records your got from the model object, use something like:

           

          @records = model.find(:all)

          recordCount = @records.count

           

          @records.each do |item|

          item.process_record

          end

           

          Having defined "process_record" in the model object.

           

          hope this helps.

          Pietro

            • Re: sync_notify, status complete yet model has zero records
              Tahir Zamir

              Hi Pietro,

               

              Thanks for the suggestion.

               

              I typed my original code incorrectly, what I actually have is:-

                  

                   @records = model.find(:count)

               

              I tried your suggestion but it didn't resolve the problem.  I thought that a sync complete notification would be a good point to do something with the records that should have been written to the local db.  Do I need a db flush command or something similar??

               

              Just to shed a bit more light on the situation, the original sync is generated by the backend and it appears to work fine as data does indeed appear on the device.   The new records are not processed as the rhodes client can't see them in the code as described above.

               

              At this point I have also tried to initiate a further sync from the web console and though I can see this sync being received on the device, the code doesn't trigger a sync complete event and my records are still left unprocessed. 

               

              I suspect that this is due to the fact that rhoconnect doesn't detect any changes between the client and backend so  a sync complete notification isn't triggered.

               

              I can initiate a manual sync from the device and interestingly this does trigger sync complete and the records are processed.

               

              Any ideas??

               

              Tahir