views:

153

answers:

1

I feel as if this should be very simple, but it's behaving strangely.

I have 3 entities, with a relationship as such

Entity A <-->> Entity B <<--> Entity C

I have an NSFetchedResults controller and I'm trying to filter the results of Entity A using the following predicate.

[NSPredicate predicateWithFormat:@"NONE entityB.entityC == %@", self.entityC];

When I try and run the app, the output shows no results. I can alter the predicate slightly to:

[NSPredicate predicateWithFormat:@"ANY entityB.entityC == %@", self.entityC];

And it shows me only the results that I want it to filter out.

Why is this happening?

+1  A: 

I think you may want a SUBQUERY expression:

@"SUBQUERY(entityB, $x, $x.entityC == %@).@count == 0"

though, it may work to do:

@"NOT (ANY entityB.entityC == %@)"

(note: I haven't tested the second option)

Barry Wark
Thank you! That worked beautifully (The first option). I had tested the formatting in the second example before, but it didn't seem to work out. I never came across SUBQUERY in the documentation, I will have to do some further reading to avoid problems in the future.
Scott Langendyk
@Scott L., unfortunately the SUBQUERY expression documentation is a little bit scattered. You should always file bug reports (http://bugreport.apple.com) or submit feedback at the bottom of the dev center pages for documentation failings such as this. The engineers are quite responsive. Good luck with your work.
Barry Wark
Thanks for the tip, I'll keep that in mind.
Scott Langendyk