Now, I need to use a predicate for a NSFetchRequest.
But things here are a little different, since there are two nested to-many relationships for the predicate to go through.
For instance, my entities are like this:

Now I need to fetch some Month and Week ManagedObjects, but the requirement is that the amount of Events of a Day of the needed Weeks or Months is more than one.
In another word, with reference to a given Week or Month, if any Day on the destination of its “days” relationship has at least one Event, then take it.
So that is a nested to-many relationship, and I don’t know how to set the predicate string.
There are two troubles:
-
I know ALL and ANY keyword. But could
@"ANY days.ANY events"be the keypath? Or how is it supposed to be? -
How to judge that the events relationship points to at least one Event object.
Would [@"%K != nil",theCorrectKeypath] work? I’m afraid of that “!= nil” does not equal to at least one destination object?
Waiting for someone to help me out.
Terribly thanks!
I found the answer my self.
There’s another way to get this, because of my condition, I can just predicate the suitable Events objects, and all the way from Events to Week or Month are to-one relationship,
so once I got the eligible Events,
I can just get corresponding Weeks and Months by
theEvent.date.thisWeek or theEvent.date.thisMonth.
Thanks for your guys,