NSPredicate master data with many relationships

I have two entities in CoreData called User and Coupon, they are in many respects. I wanted to get all coupons except those that belong to user.userId = 1, where userId is NSString.

I used: to [NSPredicate predicateWithFormat:@"NOT(ANY couponOwners.userId = %@)", @"4"]; be a predicate of my fetchedResultsController

but not filtering with the correct results. One of the Users in the Coupon coupon still has userId = 4.

Can anyone help? I’ve been stuck for a long time. Thanks in advance.

+5
source share
1 answer

Core Data predicates with "NOT ANY" do not work (this seems to be a Core Data error). In fact

[NSPredicate predicateWithFormat:@"NOT(ANY couponOwners.userId = %@)", @"4"];

returns the same result set as

[NSPredicate predicateWithFormat:@"ANY couponOwners.userId != %@", @"4"];

, , . SUBQUERY:

[NSPredicate predicateWithFormat:@"SUBQUERY(couponOwners, $c, $c.userId == %@).@count == 0", @"4"]
+11

All Articles