Skip to content
This repository was archived by the owner on Dec 5, 2019. It is now read-only.
This repository was archived by the owner on Dec 5, 2019. It is now read-only.

mergeValuesOfModel:forKeysFromManagedObject doesn't handle default key mappings #2

@jhosteny

Description

@jhosteny

If we implement the selector -mergeValueForKey:fromManagedObject:, and not -mergeValuesForKeysFromManagedObject:, the enumeration occurs over the keys provided by
+managedObjectKeysByPropertyKey.

- (void)mergeValuesOfModel:(id<MTLManagedObjectSerializing>)model forKeysFromManagedObject:(NSManagedObject *)managedObject {
    if ([model respondsToSelector:@selector(mergeValuesForKeysFromManagedObject:)]) {
        [model mergeValuesForKeysFromManagedObject:managedObject];
    } else if ([model respondsToSelector:@selector(mergeValueForKey:fromManagedObject:)]) {
        [[model.class managedObjectKeysByPropertyKey] enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *managedObjectKey, BOOL *stop) {
            [self mergeValueOfModel:model forKey:key fromManagedObject:managedObject];
        }];
    }
}

It seems like this is not the expected behavior. Shouldn't it call -managedObjectKeyForKey: to ensure that it includes default mappings? Another possibility is to just construct the _managedObjectKeysByPropertyKey by utilizing this method in the initializer.

If this does seem incorrect, I'm happy to work on a patch for the preferred fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions