2011-05-18 60 views
1

直升機傢伙,核心 - 數據NSPredicate多到多的條件

,我有以下核心數據的數據庫:

(!可惜我不能嵌入圖像,因爲垃圾郵件預防)

數據庫模型圖片:http://snapplr.com/eqx9

我想創建一個fetchRequest,其獲取所有FC對象,其fcCollection.fcSets.trainingSet屬性是在我的代碼的對象,但不是在trainingSet.memorizationSession.mistakeFCs。我想在NSFetchedResultsController中使用它。

我已經嘗試了這麼多不同的東西,他們都沒有工作(可惜我沒有保存我試過的東西,所以我不能發佈)。 但我嘗試過SUBQUERIES等。我最後的辦法是:

NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease]; 
      NSEntityDescription *entity = [NSEntityDescription entityForName: kFCMistakeEntityName 
                 inManagedObjectContext: self.managedObjectContext]; 
      [fetchRequest setEntity: entity]; 

      NSPredicate *subPredicate = [NSPredicate predicateWithFormat: 
         @"memorizationSession.trainingSet == %@", _trainingSet]; 
      [fetchRequest setPredicate: subPredicate]; 

      NSArray *mistakeFCs = [self.managedObjectContext executeFetchRequest:fetchRequest error: nil]; 

      predicate = [NSPredicate predicateWithFormat: 
         @"ANY fcCollection.fcSets.trainingSet == %@ && NOT mistakeFC in %@", _trainingSet, mistakeFCs]; 

不幸的是我收到此錯誤:

2011-05-18 22:26:55.643 testApp[9464:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'unimplemented SQL generation for predicate : (mistakeFC IN {FCMistake: empty FC; correctFC: 0, FCMistake: 55; correctFC: 9, FCMistake: empty FC; correctFC: 3, FCMistake: empty FC; correctFC: 9, FCMistake: empty FC; correctFC: 4})'

這必須有可能以某種方式!預先感謝您的幫助!

問候,金

回答

1

從謂詞編程指南:

The Core Data SQL store supports only one to-many operation per query; therefore in any predicate sent to the SQL store, there may be only one operator (and one instance of that operator) from ALL, ANY, and IN.

因此,如果您使用的是SQL數據存儲,你只能代表一個在謂詞一個一對多的關係。如果您更改爲其他持久性存儲庫,似乎意味着解除了此特定限制。