开发者

Core Data - NSPredicate to filter to-many relationship

I have 2 entities, Task and List. 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".

I'm trying to use a fetch request with an NSPredicate to get all the Task objects that belong to a specified List:

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

(where "theParent" i开发者_如何转开发s a reference to a List object). 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).

Thanks


Could it be a simple typo in your predicate?

You have "list=%@" when I assume what you really want is "list==%@"

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜