Detached CBLModel

25 views
Skip to first unread message

Daniel Ericsson

unread,
Apr 4, 2014, 10:45:40 AM4/4/14
to mobile-c...@googlegroups.com
Is there a recommended pattern to use when creating CBLModel that are
detached from a database but then at a later point attach it, when the
database is known?

So far I've had an NSObject model for detached objects that I then use
to init a CBLModel instance once I know which database it will go
into. But I have quite a number of model subclasses so I'm now looking
into if I can use CBLModel directly.

What I'm trying now to create a detached instance is:
[CBLModelSubclass modelForDocument:[[CBLDocument alloc] init]

to then actually save it when I know the database name I've resorted
to calling the private detachFromDocument.

[CBLModel valueForKey:@"detachFromDocument"];

and then setting the database property on the CBLModel which will
create a new document attached to the database.

is new API coming to support this kind of thing or am I just doing it wrong?

cheers,
-- Daniel

Jens Alfke

unread,
Apr 4, 2014, 11:02:10 AM4/4/14
to mobile-c...@googlegroups.com

On Apr 4, 2014, at 7:45 AM, Daniel Ericsson <monow...@gmail.com> wrote:

Is there a recommended pattern to use when creating CBLModel that are
detached from a database but then at a later point attach it, when the
database is known?

This isn’t currently supported. It hasn’t been on my to-do list, but it seems like a reasonable enhancement. Please file an issue on Github so we’ll remember it.

Can you clarify why this is needed in your app? For instance, why there are multiple databases and why it isn't known which database a new model will be added to?

—Jens

Daniel Ericsson

unread,
Apr 4, 2014, 11:53:21 AM4/4/14
to mobile-c...@googlegroups.com
On Fri, Apr 4, 2014 at 5:02 PM, Jens Alfke <je...@couchbase.com> wrote:

> This isn't currently supported. It hasn't been on my to-do list, but it
> seems like a reasonable enhancement. Please file an issue on Github so we'll
> remember it.
>
> Can you clarify why this is needed in your app? For instance, why there are
> multiple databases and why it isn't known which database a new model will be
> added to?

https://github.com/couchbase/couchbase-lite-ios/issues/304

thanks,
-- Daniel
Reply all
Reply to author
Forward
0 new messages