用于一对多关系的CoreData谓词 [英] CoreData predicate for one to many relationship
本文介绍了用于一对多关系的CoreData谓词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个实体:A和B. A的每个元素可以具有B的更多元素(一对多).
I have two entity: A and B. Every element of A can have more elements of B (one to many).
现在我有一个项目A,在这个项目中,我要取一个项目B(包含在A中),它具有B.field ="myParameter".
Now I have an item of A and I would to take, in this item, one item B (contained in A) that it has B.field = "myParameter".
如何为此生成谓词?
推荐答案
您可能正在寻找(已通过 MagicalRecord 测试):
You may be looking for that (tested with MagicalRecord):
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(field LIKE %@) AND (isLinkedToAObject == %@)", myFieldParameter, objectA];
使用:
ClassB
具有属性isLinkedToAObject
可以将其链接到ClassA
.
With:
ClassB
has a property isLinkedToAObject
to link it to ClassA
.
这篇关于用于一对多关系的CoreData谓词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文