我是MagicalRecord的新手,所以這可能是一件簡單的事情,但我到處尋找答案,沒有人似乎有我的問題。 我有一個簡單的核心數據結構,其中一個父導致許多Child對象與關係的孩子單向,另一個父母。MagicalRecords:無法保存簡單的關係
正如所預期的這個作品......
Parent *parent = [Parent MR_createEntity];
parent.name = @"John";
Child *child1 = [Child MR_createEntity];
child.name = @"Paul";
parent.children = [NSSet setWithObject:child];
// or child.parent = parent;
[[NSManagedObjectContext MR_contextForCurrentThread] MR_saveToPersistentStoreWithCompletion:nil];
我生成所有屬於一個家長爲孩子們的tableview,再次能正常工作。點擊一行可以進入一個顯示所選孩子詳情的控制器。該控制器具有兩個從表中傳遞給它的屬性:表所屬的父表以及被單擊的子表。
然後我有一個保存按鈕,用於對細節進行的任何更改。這觸發以下:
self.child.parent = self.parent;
/* all the other details of the child */
[[NSManagedObjectContext MR_contextForCurrentThread] MR_saveToPersistentStoreWithCompletion:nil];
[self.navigationController popViewControllerAnimated:YES];
,但我總是得到這個錯誤
CoreData: error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. The left hand side for an ALL or ANY operator must be either an NSArray or an NSSet. with userInfo (null)
2013-05-09 17:30:17.312 NoteMD[37109:c07] __70-[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:]_block_invoke21(0x815f750) Unable to perform save: The left hand side for an ALL or ANY operator must be either an NSArray or an NSSet.
我得到什麼我嘗試(如[self.parent addChildObject:self.child]同樣的錯誤或使用existingObjectWithID到獲取self.parent和self.child的本地版本)。
我猜我誤解了如何設置MagicalRecord關係,但我跑出來的東西,試圖....
編輯:這是核心數據的設置。我試圖在上面簡化它,但基本上Patient是Parent,Check是Child(患者=父母和檢查=孩子)。
此外,在應用程序委託它經由
[MagicalRecord setupCoreDataStack];
此外初始化,如果我的NSLog self.child,或在詳細視圖self.parent,無論看起來像正確的對象。
請發佈您的coreData設置屏幕截圖 – 2013-05-10 01:05:24
而不是將子設置爲父級,您可以嘗試將父級設置爲子級。映射一對一關係總是更容易。 – Anupdas 2013-05-10 06:19:56
孩子對父母是一對一的。每個家長都有很多孩子通過孩子的關係。每個孩子都有一位家長。 – 2013-05-10 16:44:35