CoreData predicate for one to many relationship

拈花ヽ惹草 提交于 2019-12-12 02:58:41

问题


I have two entity: A and B. Every element of A can have more elements of B (one to many).

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

How can I generate the Predicate for this?


回答1:


You may be looking for that (tested with MagicalRecord):

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(field LIKE %@) AND (isLinkedToAObject == %@)", myFieldParameter, objectA];

With: ClassB has a property isLinkedToAObject to link it to ClassA.



来源:https://stackoverflow.com/questions/25930232/coredata-predicate-for-one-to-many-relationship

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!