One-to-one relationship saving and initialization [iOS]


#1

I’d like to know what is the correct way to implement 1:1 relationship.

I have CalendarEvent class as CBLModel subclass and it has property of CalendarReminder (also CBLModel subclass).
There is 1:1 relationship, but i want CalendarReminder to be embedded into the same document its owner (CalendarEvent).

For now i have save method overridden and inside i first save reminder.
But there is a note to NOT override save method.

`public override func save() throws
{
if let eventReminder = self.event_reminder
{
try eventReminder.save()
}

    try super.save()
}` 

Also, i see that in this case CalendarReminder is not embedded in the same document and stored separately.
What does that mean for performance?


#2

CBLModel always represents a document; they don’t nest.

If you want an object nested inside a model, make it a class that implements the CBLJSONEncoding protocol (declared in CBLJSON.h). CBLModel understands properties of such types and encodes them as JSON objects nested inside the document.