开发者

CoreData return entities which have a relationship to >0 entities AND the count of those relationships

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].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜