一個一對多的關係,我有以下兩個實體在我的核心數據模型:核心數據 - 過濾使用謂詞
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];
你說的''「對製造商的實體過濾時」是什麼意思?如果您嘗試提取'產品',則您的請求實體必須爲'產品' –
是的。我的實體請求用於產品: –