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,
PaulIf 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].
精彩评论