Q:

Core data - how to fetch results with filter of another entity

i would like to fetch results from entity and filter the result with attribute from another entity.
i have an 2 entities:
Users{user_id,first_name,last_name}
UsersPhoneNumbers{phone_id,user_id, phone_number}
in SQL it should look like this:
select * from Users where Users.user_id in (select user_id from UsersPhoneNumbers where phone_number = '+972-54-...')

A:

You'll likely want to add a relation between your User entity and UsersPhoneNumbers.
I.e. it'll look like this:
Users{user_id,first_name,last_name,phone_number}
UsersPhoneNumbers{phone_id,user,phone_number}
Then use a fetch request based on this relationship:
NSFetchRequest* fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Users"];
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"phone_number.phone_number like[cd] %@",  @"+972-54*"];
NSArray* users = [managedObjectContext executeFetchRequest:fetchRequest error:nil];

