First of all, I have to apologize for that silly question. Unfortunately I couldn't figure out how to implement after reading so many posts. Sorry for that. So, here is my question: I have two entities, regions and counries. Each region belongs to a country and every country has several regions. In my application I chose a country and want to display all its regions.To keep it simple, country and region both have the attribute name and region has a relationship 'country'. Now I have to select all the regions of a country:
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *desc = [[model entitiesByName] objectForKey:@"Region"];
[request setEntity:desc];
NSSortDescriptor *sd = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
[request setSortDescriptors:[NSArray arrayWithObject:sd]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"any country LIKE[c] 'aCountry'"];
[request setPredicate:predicate];
That one looks nice, but doesn't work, because country is a relationship and because of this the names of the countries are not stored in the relationship, but in the entity country. I then tried another way:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"any Country.name LIKE[c] 'aCountry'"];
This results in an error:
NSInvalidArgumentException', reason: 'keypath Country.name not found in entity '
Now, what is the best way to get my regions?