小编dma*_*man的帖子

复杂的NSPredicate遍历多个实体和关系类型

由于数据库结构有点复杂,我很难解决这个谓词问题.我有以下数据库结构,或者至少是这个问题的关注点:

PUBLISHER << --- >> PUBLICIST << - BOOK << ---> AUTHOR << - >> AGENTS

我尝试了以下谓词,当我过去遍历关系时,我已经使用过,但不是这个程度.我应该提一下,我有一个带有代理名称的NSArray,我想查询数据库,以确定代理使用的出版社列表:

NSArray *agentNames = [NSArray arrayWithObjects:Dan, Hunter, Sloan, Jackson];

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

request.entity = [NSEntityDescription entityForName:@"Publisher" inManagedObjectContext:context];
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor
             sortDescriptorWithKey:@"publisherName" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)] ];
request.predicate = [NSPredicate predicateWithFormat:@"ANY pubHouse.publicist.assignedBook.authorRep.agentName IN %@", [agentNames valueForKey:@"agentName"]];
request.fetchBatchSize = 20;

    NSFetchedResultsController *frc = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:context sectionNameKeyPath:nil cacheName:nil];
Run Code Online (Sandbox Code Playgroud)

当我运行上一个谓词时,我收到以下警告:

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'unimplemented SQL generation for predicate …
Run Code Online (Sandbox Code Playgroud)

core-data objective-c key-value-observing nspredicate ios

0
推荐指数
1
解决办法
1629
查看次数