Your problem is that the relationship of one of your key paths is many to many, and the predicate does not know which object goes with it.
You have ThemeEntities<<-->>Quotes , which creates a set at each end. The quotes.author.alias key indicates "a set of instances of quotation marks, each of which is associated with instances of the author, which in turn has an alias attribute." The predicate cannot process the set.
You need to use a subquery to drag the key-key to many. A subquery is essentially a nested predicate that searches for a collection and returns a different set of objects matching the nested predicate. Subqueries are poorly documented, but they take the form:
SUBQUERY(collectionName,$collectionElementVariable,expression-with-$collectionElementVariable)
In this case, you are looking for any instances of quotes that have an author relationship with an alias corresponding to the string specified on this string. Your predicate should look like this:
@"theme.name_en=%@ AND (0!=SUBQUERY(quotes,$eachQuote,$eachQuote.author.alias=%@) .@count )",@"mytheme", @"myauthor"
The subquery says: "From the set of quotes, take each quotation object and check if its relationship object has an alias attribute corresponding to" myauthor. "Count the number of quotation objects with this match. Zero, return TRUE."
You need to use subqueries whenever you pave the way for a keyword through relationships with many.
Techzen
source share