post property whose value is the document ID of the blog post it refers to. You can model that like this:@class BlogPost;
@interface BlogComment : CBLModel
@property (assign) BlogPost* post;
@end
In the implementation of BlogComment you declare the property as @dynamic, like any other model property.
Note that the declaration uses (assign) instead of the more typical (retain). This is because a relationship to another model doesn’t retain it to avoid creating reference-loops that can lead to memory leaks. Couchbase Lite takes care of reloading the destination model if necessary when you access the property. Also, Couchbase Lite does not deallocate models with unsaved changes.
I was reading the documentation and came across this note when making a property refer to another CBLModel. I have no problem designating my relationship weak, but if I were to make an NSArray of CBLModels (to many relationship), doesn't the NSArray hold strong references to the models it contains?
I'm just trying to reconcile why CBLModel properties themselves should be weak, but arrays of CBLModels are held strongly...
@interface Book : CBLModel
@property (strong, nonatomic) NSArray* authors; // Test to-many relationship, is strong or weak???
@property (strong, nonatomic) id<CBLJSONEncoding> toc; // is this strong or weak?
@end
Oh, ok. Does that mean that the NSArray property itself should be held weak, or strong? Also, what about properties that point to NSObjects<CBLJSONEncoding>? should those be held as strong or weak?