0
我想获得一个子查询谓词工作,我很挣扎。核心数据子查询谓词
我有两个实体。
[联盟] < ---- >> [游戏]
游戏有一个属性kickOffDate
。
我想使用谓词返回所有Leagues
,它们至少有一个Game
与今天的kickOffDate。
我使用这个谓词...
// 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 >= %@)[email protected] > 0", [self startOfDay:[NSDate date]]];
NSPredicate *endOfDayPredicate = [NSPredicate predicateWithFormat:@"SUBQUERY(games, $g, $g.kickOffDate <= %@)[email protected] > 0", [self endOfDay:[NSDate date]]];
NSPredicate *compoundPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[startOfDayPredicate, endOfDayPredicate]];
然而,当我使用这个我似乎并没有得到任何结果。
我是否正确地编写了谓词?
有没有更好的方法来做到这一点?
是的,看起来是正确的。我唯一想知道的是OP没有用他的谓词得到任何结果 - 它应该给出太多的结果。 –
使用SubQuery代替复合谓词会更好吗?哪一个在什么时候使用? – Satyam