Skip to content

Instantly share code, notes, and snippets.

@blackgold9
Created August 2, 2012 23:08
Show Gist options
  • Select an option

  • Save blackgold9/3241738 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown
Author

Made this "Fix" but I'm concerned about enabling more problems down the line for people by automatically easing this one without them understanding.

@casademora
Copy link
Copy Markdown

you mean, people will just use code without understanding how and why it works?

@blackgold9
Copy link
Copy Markdown
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