Regarding CBLModel and how it saves relationships as documentIDs

99 views
Skip to first unread message

Alexander Selling

unread,
Jan 16, 2014, 3:10:40 PM1/16/14
to mobile-c...@googlegroups.com
I'm trying to find a way to opt out on this since my server side project uses inlined dictionaries/documents inside other documents.

the current implementation grabs the documentID like so:
else if ([value isKindOfClass: [CBLModel class]])
        value = ((CBLModel*)value).document.documentID;

and I'd like to just grab the properties dictionary instead but the problem is I couldn't immediately see where I should be changing the corresponding loading routine?
in other words, when the CBLModel loads the document after having saved a relationship as a dictionary instead of an ID it'll expect to see an ID when it tries to access the underlaying document and then crash when there's a dictionary there instead.

Any guidance would be helpful, thanks in advance!

Jens Alfke

unread,
Jan 16, 2014, 4:53:26 PM1/16/14
to mobile-c...@googlegroups.com

On Jan 16, 2014, at 12:10 PM, Alexander Selling <alexande...@gmail.com> wrote:

I'm trying to find a way to opt out on this since my server side project uses inlined dictionaries/documents inside other documents.

Then those shouldn't be separate documents in your database. You can implement the CBLJSONEncoding protocol (see CBLJSON.h) in a custom object class, and if you make a model property of that type the data will be stored in the model as inlined JSON.

—Jens

K Beyer

unread,
Jan 17, 2014, 11:35:02 AM1/17/14
to mobile-c...@googlegroups.com
I'd like to do the same thing ... have support for child models that don't need to be separate docs.  Currently, we have a base class which takes a NSDictionary to set up the properties ... it's used for model properties that don't have separate doc ... but the CBLJSONEncoding looks like a better approach.

Jens - Is this a good example to follow for your suggestion?

Jens Alfke

unread,
Jan 17, 2014, 11:59:41 AM1/17/14
to mobile-c...@googlegroups.com

On Jan 17, 2014, at 8:35 AM, K Beyer <kyle....@gmail.com> wrote:

I'd like to do the same thing ... have support for child models that don't need to be separate docs.  Currently, we have a base class which takes a NSDictionary to set up the properties ... it's used for model properties that don't have separate doc ... but the CBLJSONEncoding looks like a better approach.
Jens - Is this a good example to follow for your suggestion?

Yes, it sounds like CBLJSONEncoding is what you want. It's pretty simplistic, but hopefully useful. You may be interested in reading or contributing to issue 221 which describes some of its current limitations and suggests improvements.

—Jens
Reply all
Reply to author
Forward
0 new messages