On Feb 2, 2016, at 1:51 PM, Scott Ahten 
<[email protected]<mailto:[email protected]>> wrote:

- (void)awakeFromInitializer
{
    [self setValue:@"my-model" ofProperty:@"type"];
}


I don’t recommend setting any properties (especially ‘type’) in 
-awakeFromInitializer. Instead, set the ‘type’ property when creating the 
document, i.e. in the +newMyModel… method. This helps consolidate your document 
initialization code and ensures that the document can’t be declared (via its 
‘type’) as being a MyModel without having the other required properties set.

(We found a bug in ToDoLite last week that was like this. It was possible to 
load a Task model object for a nonexistent document, which led to the ‘type’ 
property being set by a method like the one above, and then autosave caused the 
bogus Task to be saved to the database. Unfortunately the document had no other 
properties, so a view’s map function that tried to operate on its listID barfed 
when it got nil.)

—Jens

-- 
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/6078DB47-245B-454E-B49B-5776A822BF1D%40couchbase.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to