Right now OR handles creating nested entity objects during update: using the classes specified in an entity's mappings block. However, when a dictionary contains multiple levels of objects, the nested dictionaries aren't processed recursively, and are treated like values for entity property keys, so -[NSManagedObject predicateForDictionary:] returns a format like: id == 4 AND type == Cajun AND owner == { id = 6 }, resulting in a crash, since the owner value is not in a valid format.
Example
Given I have a Restaurant class, an Owner class, and a Car class, where a Restaurant has an Owner and an Owner has a Car
@implementation Restaurant
+ (NSDictionary *)mappings {
return @{ @"id" : @"restaurantID",
@"owner" : @{ @"class" : [Owner class]}};
}
@end
@implementation Owner
+ (NSDictionary *)mappings {
return @{ @"id" : @"ownerID",
@"car" : @{ @"class" : [Car class]}};
}
@end
@implementation Car
+ (NSDictionary *)mappings {
return @{ @"id" : @"carID" };
}
@end
When I want to update my Restaurant instance with a dictionary that looks like so:
[restaurant update:@{
@"id" : @4,
@"type" : @"Cajun",
@"owner" : @{
@"id" : @6,
@"full_name" : @"Rory Hill"
@"car" : @{ @"id" : @43, @"model" : @"3"}}}];
Then I should have one Restaurant, one Owner, and one Car when the update is complete.
Right now OR handles creating nested entity objects during
update:using the classes specified in an entity'smappingsblock. However, when a dictionary contains multiple levels of objects, the nested dictionaries aren't processed recursively, and are treated like values for entity property keys, so-[NSManagedObject predicateForDictionary:]returns a format like:id == 4 AND type == Cajun AND owner == { id = 6 }, resulting in a crash, since the owner value is not in a valid format.Example
Given I have a
Restaurantclass, anOwnerclass, and aCarclass, where aRestauranthas anOwnerand anOwnerhas aCarWhen I want to update my
Restaurantinstance with a dictionary that looks like so:Then I should have one
Restaurant, oneOwner, and oneCarwhen the update is complete.