couchbaselabs / GrocerySync-Android

Couchbase Lite demo app for Android: A simple synced shopping list
136 stars 66 forks source link

GrocerySync-Android - as sample app toggleItemChecked .update without _rev? #23

Closed RoundSparrow closed 11 years ago

RoundSparrow commented 11 years ago

Hello.

I have a question about this as a sample app in terms of instructional purpose. When I look at the code for toggleItemChecked method... I see it does a couchbase lite .update.

What I don't see is any reference to the previous _rev

From this docs page: http://guide.couchdb.org/draft/api.html

"If you want to update or delete a document, CouchDB expects you to include the _rev field of the revision you wish to change. When CouchDB accepts the change, it will generate a new revision number."

and here: https://github.com/couchbase/couchbase-lite-ios/wiki/Guide%3A-Data-Model

"The tricky bit is that, in order to save an update to an existing document, you have to include its current revision ID. If the revision ID you provide isn't the current one, the update is rejected"

Is GrocerySync doing this somewhere that I'm not observing?

Thank you

tleyden commented 11 years ago

This is being handled by the use of the Ektorp api. When a checkbox is pushed in the UI, this code is eventually called:

        GroceryItemUtils.toggleCheck(item);
        couchDbConnector.update(item);

and as mentioned in the CouchDbConnector Ektorp Docs, it requires an existing revision number which it will use in the update. That method can also throw an exception if a conflict is detected.

Does that explain things?

RoundSparrow commented 11 years ago

ok, I think I understand the sequence.

  1. The document is read from couchbase to populate the GUI
  2. The user clicks checkbox
  3. Only one field is modified
  4. The _rev exists from the read operation in step #1 when GUI was populated

In my application, I never do any read of existing records... only update and inserts... so my problem isn't in GrocerySync. Thank you.