所以我创建了一个对象
MyObject *object = [mainManagedObjectContext insertNewObjectForEntityForName:@"MyObject"];
SomeOtherObject *someOtherObject = [s_mainManagedObjectContext insertNewObjectForEntityForName:@"MyObject"];
// in case you're wondering the inverse relationship of someOtherObject's relation ship to myObject is one to many
// so this should remove the idea that setting someOtherObjects.relationship to something else was causing the property to nil
object.oneToOneRelationShip = someOtherObject;
// simply used for debuggin
[object addObserver:self forKeyPath:@"oneToOneRelationShip" options:NSKeyValueObservingOptionInitial context:nil];
然后我使用对象管理器发布对象来发布这个东西
NSMutableURLRequest *request = [objectManager requestWithObject:object method:method path:path parameters:parameters];
[objectManager managedObjectRequestOperationWithRequest:request managedObjectContext:mainManagedObjectContext success:^{
NSLog(@"blah");
}];
现在发生这种情况之后,RestKit开始运行操作对象,这些操作对象最终会调用save,这会对此调用起作用
-(void)handleManagedObjectContextDidSaveNotification:(NSNotification *)notification {
...
[self.mergeContext mergeChangesFromContextDidSaveNotification:notification];
...
这是我的KVO观察员代码向我发出的信号,我做了一个改变
object.oneToOneRelationShip == nil
我相信我通过在发布对象之前保存到持久性存储来解决我的问题,但有人可以向我解释为什么会发生这种情况。难道我做错了什么?这个bug对我来说很混乱。我在主要背景下创建对象,所以我不知道这个问题是如何发生的。