我在CoreData中有两个实体,分别是用户和优惠券,它们是多对多的关系。我想获取除user.userId = 1所拥有的优惠券之外的所有优惠券,其中userId为NSString。
我使用:[NSPredicate predicateWithFormat:@"NOT(ANY couponOwners.userId = %@)", @"4"];作为我的fetchedResultsController的谓词
而不是用正确的结果进行过滤。优惠券的couponOwners中的一个用户仍具有userId = 4。
有人能帮帮忙吗?我已经被困了很长一段时间。提前谢谢。
发布于 2013-03-31 04:39:36
带有"NOT ANY“的核心数据谓词不起作用(这似乎是一个核心数据bug)。实际上
[NSPredicate predicateWithFormat:@"NOT(ANY couponOwners.userId = %@)", @"4"];返回与相同的结果集
[NSPredicate predicateWithFormat:@"ANY couponOwners.userId != %@", @"4"];这当然是错误的。作为解决方法,您可以使用SUBQUERY:
[NSPredicate predicateWithFormat:@"SUBQUERY(couponOwners, $c, $c.userId == %@).@count == 0", @"4"]https://stackoverflow.com/questions/15722930
复制相似问题