NSPredicate to-many relationships

ios, nspredicate, one-to-many, relationship

Solution

Based on my experience, you should change the predicate format string in

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY subcategories.items > 0"];    

from

@"ANY subcategories.items > 0"

into

@"subcategories.items.@count > 0"

Note that the ANY keyword needs to go as well, or you'll be querying the property the wrong way.

Problem

How can I find all the categories that have subcategories with more than 1 items? I am using the following code, but I get "multiple to-many keys not allowed here". Do I need to use a SUBQUERY? ``` NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Categories"]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY subcategories.items > 0"]; [request setPredicate:predicate]; ``` Help! :)

Original source