2011-01-19 57 views
0

我有一個書籍和軟件包的核心數據結構。一本書可以屬於一個或多個包,因此,我在這兩者之間有一個多對多的屬性。在這本書中,這個屬性被稱爲fromBundle。iPhone - 核心數據檢查內部NSSet屬性

我有我的課,每個實體。這個課程是在多對多的時候寫成的,所以我只有一對多的關係......所以,當時從布爾勒不是NSSet。我的問題是,我必須建立一個謂詞,它可以查看fromBundle NSSet的內部並查看該集合是否包含我正在尋找的包。

這是我在更改之前的代碼。

Bundle *aBundle = [Bundle bundleComNumber:aNumber inManagedObjectContext:context]; 


NSArray *all = nil; 

NSFetchRequest *request = [[NSFetchRequest alloc] init]; 

request.entity = [NSEntityDescription entityForName:@"Book" inManagedObjectContext:context]; 

// the problem is on the next line... as I see, the line is not looking inside the NSSet 
// I may be wrong, but when I run this, it crashes and stops on the executeFetchRequest line 
// saying **to-many key not allowed here** 

request.predicate = [NSPredicate predicateWithFormat: 
        @"(fromBundle == %@)", aBundle]; 


[request setResultType:NSDictionaryResultType]; 
[request setReturnsDistinctResults:YES]; 
[request setPropertiesToFetch:[NSArray arrayWithObjects: @"Name", @"Number", nil]]; 


NSSortDescriptor *sortByItem = [NSSortDescriptor sortDescriptorWithKey:ordem ascending:YES selector:@selector(compare:)]; 
NSArray *sortDescriptors = [NSArray arrayWithObject:sortByItem]; 
[request setSortDescriptors:sortDescriptors]; 



NSError *error = nil; 
all = [context executeFetchRequest:request error:&error]; // it is crashing here saying **to-many key not allowed here** 
[request release]; 

return all; 

我錯過了什麼? 謝謝

回答

2

您是否嘗試過使用謂詞@"%@ IN fromBundle"而不是?

+0

ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhhhhhhhhhh !!!!!!!!!!!!!!!!!!!!!!!!!!!!謝謝!!!!!我喜歡這個社區! – SpaceDog