I'm trying to get a subquery predicate to work and I'm struggling.
I have two entities.
[League] <---->> [Game]
Game has a property kickOffDate
.
I'd like to use a predicate to return all Leagues
that have at least one Game
with a kickOffDate today.
I am using this predicate...
// startOfDay and endOfDay are functions to return the given date with 00:00:00 and 23:59:59 respectively
NSPredicate *startOfDayPredicate = [NSPredicate predicateWithFormat:@"SUBQUERY(games, $g, $g.kickOffDate >= %@).@count > 0", [self startOfDay:[NSDate date]]];
NSPredicate *endOfDayPredicate = [NSPredicate predicateWithFormat:@"SUBQUERY(games, $g, $g.kickOffDate <= %@).@count > 0", [self endOfDay:[NSDate date]]];
NSPredicate *compoundPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[startOfDayPredicate, endOfDayPredicate]];
However, when I use this I don't seem to get any results.
Have I written the predicate correctly?
Is there a better way of doing this?