Hi Jens, very nice. Quick question: is or will this feature be supported on the Sync Gateway to allowing us to determine channel access rules? Based on your scenario with albums and records it may not make sense but if you apply the following scenario it could come in handy:
1) Each user has a user profile (document) 2) Account can have multiple users as "members", each represented by a user profile document With this inverse look up I could easily determine access for user profile documents (actual users are a different story) whether the user profiles should be added to the account channel. Thanks Christoph On Wednesday, February 25, 2015 at 8:14:03 PM UTC-8, Jens Alfke wrote: > > New feature available on the iOS/Mac master branch, as described in issue # > 606 <https://github.com/couchbase/couchbase-lite-ios/issues/606>: > > Added CBLModel support for computed inverse-relation properties (a typical > ORM feature, also found in Core Data.) > > For example, if the Album class has a relation @property Artist* artist (i.e. > the JSON property value is the docID of a document corresponding to an > Artist model), then it should be possible to define a property on Artist > like @property (readonly) NSArray* albums, whose value is an array of > the Albumobjects whose artist property points to the receiver. > > Behind the scenes, there's no JSON property backing this. Its value is > computed on demand by querying a view that indexes the artist property of > every album document. (If this turns out to be too slow we can cache the > value until the view index changes.) > > Caveats: > > - The property value is *recomputed on every call*. > - These properties are *not KV-observable* (that would be great to add > later, but it would require something like a LiveQuery, and would have to > be carefully optimized to be scaleable.) > > To define a property like this, you have to do three things: > 1. Define the [dynamic] property itself, with type NSArray*. > 2. Implement a class method +*property*ItemClass that returns the class > that has the inverse relation, i.e. the class of the items in the array to > be returned. > 3. Implement a class method +*property*InverseRelation that returns a > string naming the relation property in the other class that should be > queried. > > In the example: > > @interface Artist > @property (readonly) NSArray* albums; > ... > > @implementation Artist > ... > @dynamic albums; > + (Class) albumsItemClass { return [Album class]; } > + (NSString*) albumsInverseRelation { return @"artist"; } > ... > > > -- You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/7c547fa9-1a6a-4a8f-8c5b-593d75da8c21%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
