Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Ordered Sets Data Import and KVC Issues #440

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,38 +89,50 @@ - (NSManagedObject *) MR_findObjectForRelationship:(NSRelationshipDescription *)

- (void) MR_addObject:(NSManagedObject *)relatedObject forRelationship:(NSRelationshipDescription *)relationshipInfo
{
NSAssert2(relatedObject != nil, @"Cannot add nil to %@ for attribute %@", NSStringFromClass([self class]), [relationshipInfo name]);
NSAssert2(relatedObject != nil, @"Cannot add nil to %@ for attribute %@", NSStringFromClass([self class]), [relationshipInfo name]);
NSAssert2([relatedObject entity] == [relationshipInfo destinationEntity], @"related object entity %@ not same as destination entity %@", [relatedObject entity], [relationshipInfo destinationEntity]);

//add related object to set
NSString *addRelationMessageFormat = @"set%@:";
id relationshipSource = self;
if ([relationshipInfo isToMany])
if ([relationshipInfo isToMany])
{
addRelationMessageFormat = @"add%@Object:";

if ([relationshipInfo respondsToSelector:@selector(isOrdered)] && [relationshipInfo isOrdered])
{
//Need to get the ordered set
NSString *selectorName = [[relationshipInfo name] stringByAppendingString:@"Set"];
relationshipSource = [self performSelector:NSSelectorFromString(selectorName)];
relationshipSource = [self performSelector:NSSelectorFromString([relationshipInfo name])];
addRelationMessageFormat = @"addObject:";
}
}

NSString *addRelatedObjectToSetMessage = [NSString stringWithFormat:addRelationMessageFormat, attributeNameFromString([relationshipInfo name])];

SEL selector = NSSelectorFromString(addRelatedObjectToSetMessage);

@try
if ([relationshipSource respondsToSelector:selector])
{
[relationshipSource performSelector:selector withObject:relatedObject];
if (relationshipSource != self)
{
NSUInteger idx = [relationshipSource count];
NSIndexSet* indexes = [NSIndexSet indexSetWithIndex:idx];

[self willChange:NSKeyValueChangeInsertion valuesAtIndexes:indexes forKey:[relationshipInfo name]];
[relationshipSource performSelector:selector withObject:relatedObject];
[self didChange:NSKeyValueChangeInsertion valuesAtIndexes:indexes forKey:[relationshipInfo name]];
}
else
{
[relationshipSource performSelector:selector withObject:relatedObject];
}
}
@catch (NSException *exception)
else
{
MRLog(@"Adding object for relationship failed: %@\n", relationshipInfo);
MRLog(@"relatedObject.entity %@", [relatedObject entity]);
MRLog(@"relationshipInfo.destinationEntity %@", [relationshipInfo destinationEntity]);
MRLog(@"Add Relationship Selector: %@", addRelatedObjectToSetMessage);
MRLog(@"Add Relationship Selector: %@", addRelatedObjectToSetMessage);
MRLog(@"perform selector error: %@", exception);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is incorrect. We have no exception variable anymore.

}
}
Expand Down