supermarin / ObjectiveRecord

ActiveRecord-like API for CoreData
MIT License
1.29k stars 194 forks source link

Added SaveInContext to assist when working with RestKit and other SDK’s ... #83

Closed jfield44 closed 10 years ago

jfield44 commented 10 years ago

...with non standard ManagedObjectContexts

Hi I have added added another Save command called SaveInContext:(NSManagedObjectContext *)moc for use with Frameworks such as Restkit that specify a non standard MOC, this also helps in some cases where you have abstracted the initial fetch request.

Feel free to merge or ignore as desired :)

stephencelis commented 10 years ago

Hm. This could be confusing. If you change values on the object, the changes are going to be recorded on its associated context. In other words, this wouldn't work:

Person *person = [Person find:@{@"firstName": @"Stephen"} inContext:moc1];
person.firstName = @"Steve";
[person saveInContext:moc2];

If you know which MOC needs saving, why not call [moc save:&error] directly?

supermarin commented 10 years ago

@jfield44 closing this, as it really doesn't make sense.

When you create an object in a managed object context, e.g. [Person createInContext:moc], the object knows it's context. So, person.managedObjectContext would return moc