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 = [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.
精彩评论