核心数据多对多关系——谓词问题 [英] Core data many-to-many relationship - Predicate question

查看:43
本文介绍了核心数据多对多关系——谓词问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Core Data 模型中,我有两个实体:List 和 Patient.List 有一个名为name"的属性.

In my Core Data model I have two entities: List and Patient. List has an attribute called 'name'.

一个列表可以有任意数量的患者,每个患者可以属于任意数量的不同列表.因此,我在名为患者"的 List 上设置了一个与 Patient 具有一对多关系的关系,并在名为lists"的 Patient 上设置了一个与 List 具有一对多关系的关系.

A List can have any number of Patients and each Patient can belong to any number of different lists. I have therefore set a relationship on List called 'patients' that has an inverse to-many relationship to Patient AND a relationship on Patient called 'lists' that has a to-many relationship to List.

我正在努力弄清楚如何创建一个 Predicate 来选择属于特定列表名称的所有患者.

What I'm struggling to figure out is how to create a Predicate that will select all Patients that belong to a particular List name.

我该怎么做?我以前从未在 Core Data 中使用过关系.

How would I go about this? I have never used relationships before in Core Data.

推荐答案

这似乎工作正常:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(ANY lists == %@)", myList];

其中 myList 是实际的 List 实体.

Where myList is an actual List entity.

这篇关于核心数据多对多关系——谓词问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆