开发者

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

开发者 https://www.devze.com 2023-02-15 04:53 出处:网络
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 refere

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

精彩评论

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