Questions concerning CBLModel and MYDynamicObject

41 views
Skip to first unread message

Ben Kennedy

unread,
Dec 10, 2015, 4:06:07 PM12/10/15
to mobile-c...@googlegroups.com
Hey folks,

Let's say I wish to create a CBLModel subclass for a CBLDocument representing this structure:

{
"antelope" : {
"alpha" : "one",
"beta" : "two"
},
"edibles" : {
"meat" : "flesh",
"leaves" : "vegetables"
},
"beer" : "flanders sour ale"
}

In my client code, I want to be able to e.g. fetch vegetables as NSString *vegetables = someModel.edibles.leaves; .

While it is obvious from the documentation that I can create a CBLModel subclass with a @property NSString *beer, it is not clear to me how to describe the first two dictionaries.

It strikes me that I might be advised to create AntelopeModel and EdiblesModel subclasses of MYDynamicObject, and then declare such properties in my CBLModel subclass. This does not work, though, because the linker can't find MYDynamicObject when I build. (Obviously these subclasses cannot descend from CBLModel, since they are not documents themselves).

What is the correct way to do this?

Next, I have an ancillary question: is it possible, or even valid, to acquire a CBLModel object representing a specific CBLRevision of its CBLDocument?

When the time comes to resolve conflicts between versions of my document, I wish to be able to call its synthesized properties in my business logic (much as I illustrated above with the vegetables). However, since conflict resolution deals in CBLRevisions, it is not clear to me how this is possible. It appears I am left to traverse the revision.properties array directly in this case, which makes the overall value of CBLModel rather dubious, if I end up having to write everything two ways.

Do I overlook something?

thanks,

-ben

Jens Alfke

unread,
Dec 10, 2015, 6:52:47 PM12/10/15
to mobile-c...@googlegroups.com

> On Dec 10, 2015, at 1:06 PM, Ben Kennedy <ben.k...@kashoo.com> wrote:
>
> In my client code, I want to be able to e.g. fetch vegetables as NSString *vegetables = someModel.edibles.leaves; .

CBLModel only handles top-level document properties. You can use the protocol CBLJSONEncoding (declared in CBLJSON.h) to create classes that can be used as property types in a CBLModel, whose instances can populate themselves from nested properties.

> Next, I have an ancillary question: is it possible, or even valid, to acquire a CBLModel object representing a specific CBLRevision of its CBLDocument?

Unfortunately no. CBLModel always refers to a document’s current revision. What you’re asking for is great, but it would require some refactoring of CBLModel to accomplish.

After we finish 1.2 we’re going to do some design work on improving the API, and beefing up modeling is a key part of that.

—Jens

Martin Rybak

unread,
Mar 12, 2016, 3:09:03 PM3/12/16
to Couchbase Mobile
+1. Is there a Github issue for this? I couldn't fine one.

Jens Alfke

unread,
Mar 12, 2016, 3:27:20 PM3/12/16
to mobile-c...@googlegroups.com

On Mar 12, 2016, at 12:09 PM, Martin Rybak <martin...@gmail.com> wrote:

+1. Is there a Github issue for this? I couldn't fine one.

For which? Please file an issue on whichever part of that thread you think is important.

—Jens
Reply all
Reply to author
Forward
0 new messages