我的對象圖很簡單。核心數據NSPredicate for relations
我有一個feedentry對象,它存儲關於RSS提要的信息以及一個名爲Tag的鏈接到「TagValues」對象的關係。關係(to和inverse)都是to-many。即,Feed可以具有多個標籤並且標籤可以與多個Feed相關聯。
我參考How to do Core Data queries through a relationship?並創建了NSFetchRequest。但是,獲取數據的時候,我得到一個異常說明,
NSInvalidArgumentException 未實現SQL生成謂詞
我應該怎麼辦?我是一個新手,以核心數據:(我知道我已經做了一些可怕的錯誤...請幫助...
感謝
-
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"FeedEntry" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
// Edit the sort key as appropriate.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"authorname" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSEntityDescription *tagEntity = [NSEntityDescription entityForName:@"TagValues" inManagedObjectContext:self.managedObjectContext];
NSPredicate *tagPredicate = [NSPredicate predicateWithFormat:@"tagName LIKE[c] 'nyt'"];
NSFetchRequest *tagRequest = [[NSFetchRequest alloc] init];
[tagRequest setEntity:tagEntity];
[tagRequest setPredicate:tagPredicate];
NSError *error = nil;
NSArray* predicates = [self.managedObjectContext executeFetchRequest:tagRequest error:&error];
TagValues *tv = (TagValues*) [predicates objectAtIndex:0];
NSLog(tv.tagName); // it is nyt here...
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"tag IN %@", predicates];
[fetchRequest setPredicate:predicate];
// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
-
後的一些代碼,所以我們可以有一個更好看 – catsby 2009-05-29 15:17:30
Mungunth,它看起來像你可能在將謂詞重新設置爲'tag IN predicates'後,忘記設置fetchRequest的實體。如果這不是問題,請發佈對象模型的圖片,我可以給你更多的指導。 – 2009-06-02 18:01:02