核心数据多对多谓词 [英] Core Data many-to-many predicate

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

问题描述

我有两个实体通过多对多关系相关:

I have two entities which are related by a many-to-many relationship:

数据库< >>类别

换句话说,数据库可以有多个类别,一个类别可以与许多数据库相关联。

In other words, a database can have many categories and a category can be associated with many databases.

我需要一个 NSPredicate ,它将返回与给定数据库对象相关联的所有类别对象。任何帮助将不胜感激。

I need an NSPredicate that will return all Category objects associated with a given database object. Any help would be appreciated.

推荐答案

您不需要一个谓词。假设您有一个称为类别的关系,这是与您的类别实体的对多关系,则

You don't need a predicate. Given that you have a relationship called categories that is the to-many relationship to your Category entities, then

NSSet *categoriesForDatabase = database.categories;

如果你真的想使用谓词,那么它将是:

If you really want to use a predicate then it would be:

[NSPredicate predicateWithFormat:@"ANY databases = %@", database];

其中databases是Category实体上的多对多关系的名称,数据库是一个实例的数据库实体。

where "databases" is the name of the to many relationship on the Category entity and database is an instance of a Database entity.

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

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