How to recover a deleted document when you have a CBLModel object (aka undo a delete)

34 views
Skip to first unread message

Brendan Duddridge

unread,
Oct 7, 2015, 4:58:52 PM10/7/15
to Couchbase Mobile
Hi,

There was some talk about adding NSUndoManager support back in 2013, but I don't know if anything has happened with that.

So I am trying to implement undo of deletions and I'm wondering if there's a way to recover the most recently deleted CBLDocument given the fact that I still have the CBLModel hanging around in my undo stack?

According to the header file for CBLModel:

/** Deletes the document from the database. 

    You can still use the model object afterwards, but it will refer to the deleted revision. */

- (BOOL) deleteDocument: (NSError**)outError;


So does that mean that I can somehow get the deleted revision from the model object and somehow reconstitute the CBLDocument that this model object used to refer to?


Thanks,

Brendan

Jens Alfke

unread,
Oct 7, 2015, 5:31:42 PM10/7/15
to mobile-c...@googlegroups.com

On Oct 7, 2015, at 1:58 PM, Brendan Duddridge <bren...@gmail.com> wrote:

So does that mean that I can somehow get the deleted revision from the model object and somehow reconstitute the CBLDocument that this model object used to refer to?

The .document property should still be valid. You could reconstitute the previous revision by getting its contents and then saving those as a new revision. Just be aware that there’s no guarantee the previous revision’s body will still be available — if the database has compacted after the deletion, it’ll be gone. (With SQLite you’d have to manually compact it, but ForestDB databases now auto-compact in the background.) The only way to reliably restore the old revision would be if you cached it in your undo object.

—Jens
Reply all
Reply to author
Forward
0 new messages