Complex master data predicate with to-many relationship

I have 3 objects. Folder, Feed and FeedItem

I need to get folders that have feeds and feeds that have unread FeedItems

NSPredicate * predicate = [NSPredicate predicateWithFormat:@" feeds.@count > 0 AND feeds.feedItems.unread == 0 "];

I get this error

'NSInvalidArgumentException', reason: the to-many key is not allowed here

How to build such a predicate? Is it possible at all?

+5
source share
1 answer

I do not like it feeds.feedItems.unread==0, because it feedsand feedItemsreturn a set, so the predicate does not know which object to test.

Give it a try ANY feeds.feedItems.unread==0.

. FeedItem unread==0, feed.folder .

, , , , . .


:

, , SUBQUERY. :

NSPredicate *p = [NSPredicate predicateWithFormat:@"(0 != SUBQUERY(feeds, $x, (0 != SUBQUERY($x.feedItems, $y, $y.unread==0).@count)).@count)"];

, . :

SUBQUERY(objects, singleObjectVariable, expression-for-single-object)

, , , . , , .

+24

All Articles