I'm scratching my head on this one. I have a work around, but I don't understand it so that doesn't count. What I want to do is for the entity (in this case a "Photo" lets say), I want to find all the Photos reviewed by anyone OTHER than the specified user. The relationship here is Photo->Review->User, where a photo can have multiple reviews, and each review is owned by exactly one user. The first two examples were my logical first attempts, but does not work. I found some similar code that shows the subquery which works, but can anyone explain why the first two examples don't work?
// this does not work
[NSPredicate predicateWithFormat:@"NOT (ANY reviews.user = %@)", self.user]
// this does not work
[NSPredicate predicateWithFormat:@"NONE reviews.user = %@", self.user]
// this works
[NSPredicate predicateWithFormat:@"SUBQUERY(reviews, $x, $x.user == %@).@count == 0", self.user];
try this
NSPredicate *predicate = [NSCompoundPredicate notPredicateWithSubpredicate:[NSPredicate predicateWithFormat:@"ANY reviews.user = %@", self.user]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With