How to filter entities by many relationship count using SUBQUERY in Core Data

Viewed 35

I would like to get a list of cities that have location with more than 3 checkins.

city -> locations -> checkins

It seems I tried every possible subquery and I keep getting obscure errors. Would really appreciate some help.

"SUBQUERY(locations, $l, $l.checkins.@count > 3).@count != 0"

'Keypath containing KVC aggregate where there shouldn't be one; failed to handle $l.checkins.@count'

1 Answers

The predicate parser seems to recognise both the KVC aggregate functions, like @count and @sum, and the NSExpression functions like count: - I think you can use the latter, like this:

"SUBQUERY(locations, $l, count:($l.checkins) > 3).@count != 0"
Related