CoreData - 使用NSSet的NSPredicate [英] CoreData - NSPredicate with NSSet

查看:144
本文介绍了CoreData - 使用NSSet的NSPredicate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下关系的数据库:





A<< - >> B



表; B:活动表



会员有很多活动,每个活动有很多会员。因此,一个多对多的关系。



当用户从tableView中选择一个Activity时,一个新的tableView应该被所有具有该Activity的成员推送。 p>

在childtableView的NSPredicate中,我执行:

  request.entity = [NSEntityDescription entityForName:@MembersinManagedObjectContext:context]; 
request.predicate = [NSPredicate predicateWithFormat:@memberActivity =%@,[NSSet setWithObject:activity]];

结果是:


***由于未捕获的异常而终止应用程序
'NSInvalidArgumentException',原因:此处不允许包含多个键


我做错了什么?



感谢,



RL

解决方案

尝试

  request.predicate = [NSPredicate predicateWithFormat:@self in%@,[activity hasMembers]]; 



我并没有做这么复杂的CoreData,但我的理解是,查询应该返回所有使用由CoreData维护的托管对象ID在hasMembers集中的成员对象。让我知道它是怎么回事。


I have a DB with the following relationships:

A <<-->> B

A: Members table; B: Activities table

A Member has many Activities, and each Activity has many Members. So, a many to many relationship.

When the user selects an Activity from a tableView, a new tableView should be pushed with all the Members that has that Activity.

In the NSPredicate of the "child" tableView, I do:

request.entity = [NSEntityDescription entityForName:@"Members" inManagedObjectContext:context];    
request.predicate = [NSPredicate predicateWithFormat:@"memberActivity = %@", [NSSet setWithObject:activity]];

And the result is:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'to-many key not allowed here'

What am I doing wrong?

Thanks,

RL

解决方案

Try

request.predicate = [NSPredicate predicateWithFormat:@"self in %@", [activity hasMembers]];

I haven't done much of this complexity with CoreData, but my understanding is that query should return all the Member objects that are in the hasMembers set, using the managed object ID maintained by CoreData. Let me know how it goes.

这篇关于CoreData - 使用NSSet的NSPredicate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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