1 Answer
1

Your problem is that the relationship of one of you keypath is a to-many, to-many and the predicate does not know which particular object goes with which.

You have ThemeEntities<<-->>Quotes which is produces a set at each end. The quotes.author.alias keypath says "a set of quotes instances, each linked to author instances which in turn has an alias attribute." The predicate cannot process the set.

You need to use a subquery to jump a to-many keypath. The subquery is essentially a nested predicate which searches a set and returns another set of objects matching the nested predicate. Subqueries are poorly documented but they have the form:

The subquery says, "Of the set of quotes, take each quote object and test if its author relationship object has an alias attribute matching 'myauthor'. Count the number of quote objects with that match. If the number is non-zero, return TRUE."

You need to use subqueries whenever you walk a keypath across a to-many relationship.

Thanks heaps for this great answer. I didn't know about the subqueries and it's definitely very helpful. In my case however I wanted to filter the set of quotes returned by the request "inside" all the ThemeEntries. Using the subquery can filter the returned entries, making sure that they have a relationship with the author through the quotes they are related to. What I finally did is getting ALL the quotes related to the theme without filtering the author and filtered them afterward. But I still wonder if there is a way of doing it directly in the request (like a left join would do in sql)
–
BenSep 6 '10 at 0:35

Not exactly sure what you are looking for but the above predicate only searches those Quote instances linked to specific ThemeEntities instances. In fact, owing to how predicates are evaluated, it will only check those Quote instances for ThemeEntities that pass the first test.
–
TechZenSep 6 '10 at 20:15

Thank you for solving this @TechZen !!! Damn, I was struggling with this for hours, trying to figure out a way to make a compound predicate that applies a filter using two criteria for the same collection element. This was incredibly easy with the help of your answer. Thanks!
–
Greg CombsNov 22 '11 at 20:56