Reputation: 1141
I have a CoreData model with an object "bar" which has a to-many relationship "drinks" to the entity "drink".
The entity drink has only one attribute called "name".
Now in my app I have a tableView that shows all the bars and has a searchBar included.
In this searchBar I would like to be able to search for the name, location and the possible drinks that are available in a bar.
I have already implemented the name and the location like this:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"
name contains[cd] %@ OR
location.name_extern contains[cd] %@ OR
location.name_intern contains[cd] %@",
searchText, searchText, searchText];
So now my question is: How can I search for the name attribute in the NSSet of drinks?
EDIT:
To make it more clear, here are the important data models:
Bar
Attributes:
name
location
drinks
Location
Attributes:
name_extern
name_intern
Drink:
Attributes:
name
I have a searchText
and need to check the following 4 places whether it matches something:
Upvotes: 3
Views: 1236
Reputation: 53102
Something like this should work:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"
name contains[cd] %@ OR
location.name_extern contains[cd] %@ OR
location.name_intern contains[cd] %@ OR
ANY location.drinks.name contains[cd] %@",
searchText, searchText, searchText, searchText];
Upvotes: 4