2011-08-29 52 views
2

我有一個分貝以下關係式:CoreData - NSPredicate與NSSet中

enter image description here

一個< < - >> B

答:會員表; B:活動表

會員有很多活動,每個活動都有很多會員。所以,多對多的關係。

當用戶從tableView中選擇一個活動時,應該將一個新的tableView與所有具有該活動的成員一起推送。

在 「孩子」 的tableView的NSPredicate,我做的:

request.entity = [NSEntityDescription entityForName:@"Members" inManagedObjectContext:context];  
request.predicate = [NSPredicate predicateWithFormat:@"memberActivity = %@", [NSSet setWithObject:activity]]; 

,其結果是:

***終止應用程序由於未捕獲的異常 'NSInvalidArgumentException' 的,原因:'to-many key not permitted here'

我在做什麼錯?

感謝,

RL

回答

7

嘗試

request.predicate = [NSPredicate predicateWithFormat:@"self in %@", [activity hasMembers]]; 

我沒有做太多這與CoreData複雜的,但我的理解是,查詢應該返回是在所有會員對象hasMembers使用由CoreData維護的託管對象ID進行設置。讓我知道事情的後續。

+0

完美! 謝謝:) –