title: iOS Core data predicate for one-to-many
body: <p>I have two entities as illustrate on the figure. I need to fetch a particular appointment and all the related attendees where attendee is not deleted (hasDeleted != 1). I have tried with different predicate formats. Following are two main predicate I have tried and not able to get the any of these predicates work. Could you please help me to overcome this issue?</p>
  
  <pre><code>NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"objectName = %@ AND objectId = %i AND SUBQUERY(attendees, $x, $x.hasDeleted != 1).@count != 0", [self.userDefaults stringForKey:OBJECT_NAME], [[self.userDefaults objectForKey:OBJECT_ID] intValue]];
  NSPredicate *predicate2 = [NSPredicate predicateWithFormat:@"objectName = %@ AND objectId = %i AND (ANY attendees.hasDeleted != 1)", [self.userDefaults stringForKey:OBJECT_NAME], [[self.userDefaults objectForKey:OBJECT_ID] intValue]];
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/YviCn.png" alt="Appointment and Attendee entities"></p>
  
  <p>Appointment list tableview </p>
  
  <p><img src="https://i.stack.imgur.com/rhKin.png" alt="enter image description here"></p>
  
  <p>Detail appointment view where the attendee details can be seen. 
  <img src="https://i.stack.imgur.com/xHr1m.png" alt="enter image description here"></p>
  
  <p>Fetch result controller code: </p>
  
  <pre><code>- (NSFetchedResultsController *)fetchedResultsController
  {
      if (_fetchedResultsController != nil) {
          return _fetchedResultsController;
      }
      NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
      NSEntityDescription *entity = [NSEntityDescription entityForName:@"Attendee" inManagedObjectContext:self.managedObjectContext];
      [fetchRequest setEntity:entity];
  
      NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"uuid" ascending:NO];
      NSArray *sortDescriptors = @[sortDescriptor];
  
      [fetchRequest setSortDescriptors:sortDescriptors];
  
      NSPredicate *predicate = [NSPredicate predicateWithFormat:@"appointment.objectName = %@ AND appointment.objectId = %i AND hasDeleted != 1", [self.userDefaults stringForKey:OBJECT_NAME], [[self.userDefaults objectForKey:OBJECT_ID] intValue]];
  
      [fetchRequest setPredicate:predicate];
  
      NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
      aFetchedResultsController.delegate = self;
      self.fetchedResultsController = aFetchedResultsController;
  
      NSError *error = nil;
      if (![self.fetchedResultsController performFetch:&amp;error]) {
          NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
          abort();
      }
      return _fetchedResultsController;
  }
  </code></pre>