简体   繁体   English

核心数据 - NSPredicate可过滤多对多关系

[英]Core Data - NSPredicate to filter to-many relationship

I have 2 entities, Task and List. 我有2个实体,任务和列表。 Each task has a to-one relationship to a List object called "list", and there is an inverse relationship with List, which has a to-many relationship with Task called "tasks". 每个任务与一个名为“list”的List对象具有一对一的关系,并且与List有一个反向关系,它与Task有一个to-many关系,称为“tasks”。

I'm trying to use a fetch request with an NSPredicate to get all the Task objects that belong to a specified List: 我正在尝试使用带有NSPredicate的获取请求来获取属于指定List的所有Task对象:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"list=%@", theList];
[fetchRequest setPredicate:predicate];

(where "theParent" is a reference to a List object). (其中“theParent”是对List对象的引用)。 However this returns no fetched objects. 但是,这不会返回任何提取的对象。 If I take out the predicate, then the objects are returned (so I do know they exist, and by NSLogging theList I know it has Task objects associated with it). 如果我拿出谓语,然后返回的对象(所以我不知道它们的存在,并通过NSLogging theList我知道它已经任务对象与之相关联)。

Thanks 谢谢

Could it be a simple typo in your predicate? 这可能是你谓词中的一个简单错字吗?

You have "list=%@" when I assume what you really want is "list==%@" 当我假设你真正想要的是“list ==%@”时,你有“list =%@”

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"list == %@", theList];
[fetchRequest setPredicate:predicate];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM