Skip to content

Instantly share code, notes, and snippets.

@blackgold9
Created August 2, 2012 23:08
Show Gist options
  • Save blackgold9/3241738 to your computer and use it in GitHub Desktop.
Save blackgold9/3241738 to your computer and use it in GitHub Desktop.
Made this "fix" to MR_inContext
- (id) MR_inContext:(NSManagedObjectContext *)otherContext
{
__block NSError *error;
if ([self.objectID isTemporaryID]) {
if (otherContext.parentContext == self.managedObjectContext)
{
// We have a temporary id, which can never be used to lookup accross contexts, but we're trying it from a child context, so we can just get it
[self.managedObjectContext performBlockAndWait:^{
MRLog(@"Automatically obtaining a permanent Id so we can find it in a child context");
[self.managedObjectContext obtainPermanentIDsForObjects:[NSArray arrayWithObject:self] error:nil];
[MagicalRecord handleErrors:error];
error = nil;
}];
} else {
MRLog(@"Unable to obtain a permanent Id for object. [NSManagedObject MR_inContext:] will not succeed");
}
}
NSManagedObject *inContext = [otherContext existingObjectWithID:[self objectID] error:&error];
[MagicalRecord handleErrors:error];
return inContext;
}
@blackgold9
Copy link
Author

blackgold9 commented Aug 2, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment