我有一个模型:
地点<--->>分类
执行以下查询时:
NSFetchRequest *req = [NSFetchRequest fetchRequestWithEntityName:@"Category"];
if(![searchText isEqualToString:@""] && searchText != nil){
req.predicate = [NSPredicate predicateWithFormat:@"(places.placeTitle contains %@) OR (places.details contains %@) OR (name contains %@)", searchText, searchText, searchText];
NSLog(@"ModelHelper.getResults: Search text given, creating predicate: %@", req.predicate);
}
req.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name"
ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)]];
NSFetchedResultsController *controller = [[NSFetchedResultsController alloc]initWithFetchRequest:req
managedObjectContext:context
sectionNameKeyPath:nil
cacheName:nil];
NSError *error = nil;
[controller performFetch:&error];
我收到不应该存在的匹配项,例如:
searchText = "1234"
第一个结果是:
category[0].name = "Bars"
category[0].places[0].placeTitle = "Aaa"
category[0].places[0].details = "Aaa"
category[0].places[1].placeTitle = "123456"
category[0].places[1].details = "123456"
category[0].places[2].placeTitle = "test"
category[0].places[2].details = "test"
我的谓词有什么问题吗?谢谢。