Best practices for setting updated_at and updated_by_user?

29 views
Skip to first unread message

Drew Wilson

unread,
Sep 24, 2015, 7:37:06 PM9/24/15
to Couchbase Mobile
I want to record the user who last updated a document and the time of modification.

What's the best practice for to update my model object's updated_at timestamp?

I'd like to do this in the Sync Gateway's mapping function, so that my application(s) doesn't have to implement this, and to simplify my application's update logic.

If this isn't advisable, where should I do this? CBLModel:willSave:?

And is there a way to get the current user used by the replicator? Or should I just store this myself on my datastore object?

Thanks,

Drew

Jens Alfke

unread,
Sep 24, 2015, 8:30:29 PM9/24/15
to mobile-c...@googlegroups.com
On Sep 24, 2015, at 4:22 PM, Drew Wilson <drewm...@gmail.com> wrote:

I'd like to do this in the Sync Gateway's mapping function, so that my application(s) doesn't have to implement this, and to simplify my application's update logic.

You can’t; the sync function can’t modify the revision it’s working on. 

Revisions are created by clients, and all Sync Gateway does is store and transmit them. (OK, you can create revisions in Sync Gateway by using its REST API, but that’s different from replication.)

If this isn't advisable, where should I do this? CBLModel:willSave:?

Yup, that’s a good place.

And is there a way to get the current user used by the replicator? Or should I just store this myself on my datastore object?

You’d have to remember it yourself.

—Jens
Reply all
Reply to author
Forward
0 new messages