I have a to-many (optional) relationship from entity A to entity B via the ‘ref’ field and I’m using the following predicate to only return A entities which have one or more references:
NSPredicate *tagsPredicate = [NSPredicate predicateWithFormat:@"ref.@count > 0"];
[fetchRequest setPredicate:tagsPredicate];
Using this predicate I can populate my table view with fields from entity A, e.g. A.name. However I would also like to retrieve and display the count of references to the B entities, i.e. the value of ref.count value.
Thanks,
Paul
If the question is “how do I get the count of objects that A.ref points to?”, one possible answer is: [A valueForKeyPath:@”ref.@count”]. Another is: [A.ref count].