Reputation: 2562
I have a many-to-many relationship between tables, and I populate a tableView with Activities. For that i user a simple NSPredicate like this:
request.predicate = [NSPredicate predicateWithFormat:@"deleted == %@", [NSNumber numberWithBool:NO]];
How can I do to show only the Activities that has Members attached to it?
I think that in the NSPredicate I have to do some count so that only the Activities with count > 0 are returned. Is that so? How?
(i'm newbie in coredata...)
Thanks,
RL
Upvotes: 1
Views: 2083
Reputation: 25429
You need to add a subquery to your predicate acting on the CompanyActivity entity as follows:
[[NSPredicate predicateWithFormat:@"deleted == %@" && (0 >= SUBQUERY(Members, $sub, $sub.deleted == %@).@count)", [NSNumber numberWithBool:NO] [NSNumber numberWithBool:NO]];
The first part of the predicate returns objects which have not been deleted, the second one related to the subquery will take care of retrieving all those CompanyActivity objects whose Members have not been deleted.
Upvotes: 4