2009-05-29 104 views
10

我的对象图很简单。核心数据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; 

-

+1

后的一些代码,所以我们可以有一个更好看 – catsby 2009-05-29 15:17:30

+0

Mungunth,它看起来像你可能在将谓词重新设置为'tag IN predicates'后,忘记设置fetchRequest的实体。如果这不是问题,请发布对象模型的图片,我可以给你更多的指导。 – 2009-06-02 18:01:02

回答

3

你需要SQLite吗?我正在处理类似的问题,并且发现一切都按照预期在二进制存储中工作。
使用SQLite作为存储时有一些限制,尽管我还没有找到列出限制,只有他们存在。

对不起,我不能有更多的帮助。

相关问题