title: iOS Core data how to use NSPredicate to find parent objects based on one to many child properties?
body: <p>I have a Core Data model that goes as following:</p>
  
  <p>A <code>ServiceProvider</code> Entity can have many <code>Service</code> Entities(one to many relationship). Each Service has a <code>type</code> attribute.</p>
  
  <p>How can I use the <code>type</code> attribute of the <code>Service</code> entity to search for <code>ServiceProviders</code> that have services with that type?</p>
  
  <p>Below is an example that I currently have that works for a single service relationship. <strong>How can I modify the predicate below to work for multiple services?</strong></p>
  
  <pre><code>  NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
      NSManagedObjectContext* context = [HealthDataManager sharedInstance].managedObjectContext;
  
      NSEntityDescription *entity = [NSEntityDescription entityForName:@"ServiceProvider" inManagedObjectContext:context];
      [fetchRequest setEntity:entity];
  
  
  
      [fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"self.service.type == %i",type]];
  
      NSArray* results = [context executeFetchRequest:fetchRequest error:nil];
  
      if(results.count&gt;0)
      {
          for(ServiceProvider* provider in results)
          {
              DLog(@"found provider: %@", [provider description ]);
          }
          return [results lastObject];
      }else{
          DLog(@"Creating provider" );
      }
  </code></pre>