Skip to content

MR_inContext fails because object has temporary ID #312

Closed
tonymillion opened this Issue Nov 17, 2012 · 6 comments

4 participants

@tonymillion

I just came across this, an object created & persisted in another context still had a temporary ID assigned to it, which caused MR_inContext to get a Cocoa 13300 Error.

I dont have the time to make a pull request at the moment (I've not even got a personal fork of Magical Record at the moment), but here is the code I did to fix this problem.

-(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];
        }
    }

    error = nil;

    NSManagedObject *inContext = [otherContext existingObjectWithID:[self objectID] error:&error];
    [MagicalRecord handleErrors:error];

    return inContext;
}
@casademora
Magical Panda Software member
@NealEhardt

Thank you! This fix really helped me.

Since I had to fork the repo, I went ahead and submitted a pull request. #378

@tonymillion

Dammit I submitted this as a pull request ages ago and it was rejected. I think I'm done helping MagicalRecord.

@tonymillion

see #319

@tonyarnold

I'm not sure why your original pull request was closed without explanation, but I'll find out and we'll get this sorted out. It's possible that it was closed because the pull request was made against the master branch, and not develop where we merge in changes before release, but you should have been provided an explanation.

I should leave it at that… while I can understand your frustration over your fix not being merged, looking after this project is an unpaid gig, and there are only 3 of us on the team. Mistakes and oversights happen, and over the last month or so the focus was on fixing up problems with the save methods. The best we can do is apologise and do our best to prevent this from happening again.

@tonymillion

That came out way grumpier than it should have done, so I apologise (this is after a few fairly involved twitter / app.net discussions). I shouldn't post before I've had my morning coffee.

side note: I dont actually use MagicalRecord, but I have looked at it in the past so any fixes I do post are usually just to help out :)

@tonyarnold tonyarnold was assigned Aug 19, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.