Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Dictionaries nested more than 1 level deep break findOrCreate: #60

Description

@kattrali

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions