开发者

CoreData - NSPredicate with NSSet

开发者 https://www.devze.com 2023-03-31 19:34 出处:网络
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 relations

I have a DB with the following relationships:

CoreData - NSPredicate with NSSet

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 = [NSP开发者_开发知识库redicate 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.

0

精彩评论

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

关注公众号