Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

MR_inContext: works on objects with temporary IDs #379

Closed
wants to merge 2 commits into from

2 participants

@NealEhardt

This is in response to Issue 312.

@tonyarnold
Owner

I'm closing this PR in favour of #540 (which doesn't include the unnecessary merge, but still credits you directly for the change). I'm going to write some tests for this in the morning before I merge it into develop properly — thanks for the PR, and please accept my apologies for taking so long to merge the changes in.

@tonyarnold tonyarnold closed this
@tonyarnold tonyarnold was assigned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
13 MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalRecord.m
@@ -222,6 +222,19 @@ + (BOOL) MR_truncateAll
- (id) MR_inContext:(NSManagedObjectContext *)otherContext
{
NSError *error = nil;
+
+ if (self.objectID.isTemporaryID)
+ {
+ BOOL success = [self.managedObjectContext obtainPermanentIDsForObjects:@[self] error:&error];
+ if (!success)
+ {
+ [MagicalRecord handleErrors:error];
+ return nil;
+ }
+ }
+
+ error = nil;
+
NSManagedObject *inContext = [otherContext existingObjectWithID:[self objectID] error:&error];
[MagicalRecord handleErrors:error];
Something went wrong with that request. Please try again.