Using the NSPredicate SUBQUERY

This is the relevant part of my object:

Store <-->> Gift <<--> Person <<-->> Tag

I would like to be able to filter stores by tag.filtering attribute, for example:

ANY gifts.person.tags.filtering == YES

But I understand why this does not work due to the restriction on keys from one to many. Therefore, I am trying to use a set of nested predicates SUBQUERY, for example:

NSPredicate* filterPredicate = [NSPredicate predicateWithFormat:
   @"(0 != SUBQUERY(gifts, $x, 
     (0 != SUBQUERY($x.person.tags, $y, $y.filtering==YES).@count)).@count)"];

This does not execute at runtime with an error:

"SQLite error code:1, 'no such column: t3.ZFILTERING'"

I seem to be on the right track here, but can't find other examples that use the same syntax. What am I missing?

+4
source share
1 answer

From my comment above:

[NSPredicate predicateWithFormat:@"SUBQUERY(gifts, $x, ANY $x.person.tags.filtering == YES).@count != 0"]

works and is even simpler than nested SUBQUERY.

+7
source

All Articles