2011-01-19 3 views
0

私は書籍とバンドルのコアデータ構造を持っています。 1つの本は1つ以上のバンドルに属することができるので、2つの間に多対多の属性があります。本書では、この属性はfromBundleと呼ばれています。フェッチのNSSet属性内でiPhone - コアデータの検査

私は各エンティティに自分のクラスを持っています。このクラスは、多対多の関係を持っていた時に書かれました。その時、fromBundleは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

hhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh !!!!!!!!!!!!!!!!!!!!!!!!!!!! ThAnKs !!!!!私はこのコミュニティが大好き! – SpaceDog