一个一对多的关系,我有以下两个实体在我的核心数据模型:核心数据 - 过滤使用谓词
Manufacture {name, ...other attributes}
Product {name, .... other attributes}
我已经建立了一对多的关系:
Manufacturer.manufactures <------>> Product.manufacturedBy
我我试图构建一个谓词来返回属于制造商的与搜索字符串匹配的所有产品。例如。如果有两个制造商,“国王螺母”和“女王坚果”,则搜索“坚果”应该返回由国王螺母和皇后螺母制造的所有产品。
当我的过滤器位于产品实体上时,我的谓词完美地工作,但是当在制造商实体上过滤时,我无法获取任何谓词。结果集是空的。
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Product" inManagedObjectContext:[GBKDB context]];
searchValue = @"nut";
NSString *wildcardString = [NSString stringWithFormat:@"*%@*", searchValue];
我曾尝试以下:
predicate = [NSPredicate predicateWithFormat:@"manufacturedBy.name CONTAINS[cd] %@",searchValue];
predicate = [NSPredicate predicateWithFormat:@"manufacturedBy.name like %@",wildcardString];
predicate = [NSPredicate predicateWithFormat:@"manufacturedBy.name matches %@",wildcardString];
predicate = [NSPredicate predicateWithFormat:@"ALL manufacturedBy.name like %@",wildcardString];
predicate = [NSPredicate predicateWithFormat:@"ALL manufacturedBy.name like[cd] %@",@wildcardString];
你说的''“对制造商的实体过滤时”是什么意思?如果您尝试提取'产品',则您的请求实体必须为'产品' –
是的。我的实体请求用于产品: –