Updating a CBLModel vs doc update method.

15 views
Skip to first unread message

Todd Freese

unread,
Apr 24, 2017, 7:38:35 PM4/24/17
to Couchbase Mobile
When changing a CBLModel property and saving the model, does it use the CBLDocument update method?

Is there any advantage to instead do a:

Event *event = ... // where event is a CBLModel.

CBLDocument *doc = event.document;

NSError* error;

if (![doc update: ^BOOL(CBLUnsavedRevision *newRev) {

    newRev[@"eventStatus"] = @"PENDING";

    return YES;

} error: &error]) {

    NSLog(@"Error saving event. %@", error);

}


Todd



Brendan Duddridge

unread,
Apr 27, 2017, 2:41:38 PM4/27/17
to Couchbase Mobile
I just use the CBLModel save function. I only drop down to the CBLDocument level when I need to do bulk changes to documents.

I don't know if there's a difference though because as far as I understand, when the underlying CBLDocument is changed, that propagates to the CBLModel.

Jens Alfke

unread,
Apr 27, 2017, 5:19:04 PM4/27/17
to Couchbase Mobile

On Apr 24, 2017, at 4:38 PM, Todd Freese <to...@filmworkers.com> wrote:

When changing a CBLModel property and saving the model, does it use the CBLDocument update method?

It calls -[CBLDocument putProperties:error:].
Saving directly to the document will work, but has a bit more overhead because the model hears about the change secondhand and has to invalidate all its property values and send KVO notifications for each of them.

—Jens
Reply all
Reply to author
Forward
0 new messages