I have 2 entities with a one to many relationship. Category represents my section headers and SubSubCategory represents my rows.
Category
{
name:string
subs<-->>SubCategory
}
SubCategory
{
name:string
numbervalue:NSNumber
}
Currently I can use NSPredicate to filter my sections based on name.
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name==%@",@"anamevalue"];
Now I want to further filter this predicate to only return categories that have a Subcategory with a subvalue == 1.
How can I filter the Category entity based on the values in its one to many children?
I tried something like this but its no good.
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name==%@ AND subs.numbervalue==%@",@"anamevalue",1];
I’ll do a predicate like the following:
The
ANYis a predicate modifier that returns true only if there is at least one object in subs collection for which the comparison returns true.The same result could be done by means of
SUBQUERY.Hope it helps.