Core Data - NSPredicate to filter to-many relationship
I have 2 entities, Task and List. Each task has a to-one relationship to a List object called "list", and there is an inverse relationship with List, which has a to-many relationship with Task called "tasks".
I'm trying to use a fetch request with an NSPredicate to get all the Task objects that belong to a specified List:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"list=%@", theList]; [fetchRequest setPredicate:predicate];
(where "theParent" is a reference to a List object). However this returns no fetched objects. If I take out the predicate, then the objects are returned (so I do know they exist, and by NSLogging theList I know it has Task objects associated with it).
Could it be a simple typo in your predicate?
You have "list=%@" when I assume what you really want is "list==%@"
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"list == %@", theList]; [fetchRequest setPredicate:predicate];