title: NSPredicate for one-to-many relationship give duplicate results
body: <p><a href="https://i.stack.imgur.com/PS5Yg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PS5Yg.png" alt="enter image description here"></a>I have 2 entities (Category and SubCategory) with a one to many relationship. I want to show categories in the tableView with each category represent one section in tableView (Category name will be the title of header view and all its associated subCategories will be the rows). I have to exclude the subcategories with 'isActive == NO'.
  To achieve this I created NSFetchRequest on Category entity as below.</p>
  
  <pre><code>NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
  NSEntityDescription *entity = [NSEntityDescription entityForName:@"Category" inManagedObjectContext:moc];
  NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY subCategories.isActive == YES"];
  [fetchRequest setPredicate:predicate];
  [fetchRequest setEntity:entity];
  </code></pre>
  
  <p>But this fetch request gives multiples(Duplicate) Categories. i.e If total subCategories with "isActive == YES" is 25, I'm getting 25 Categories in the fetchedResult.</p>
  
  <p>I also tried with "SUBQUERY", and with this I'm not getting duplicated categories but I'm getting all the SubCategories irrespective of "isActive == YES".</p>
  
  <pre><code>NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
  NSEntityDescription *entity = [NSEntityDescription entityForName:@"Category" inManagedObjectContext:moc];
  NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(SUBQUERY(subCategories, $x, ($x. isActive == 1)).@count != 0)"];
  [fetchRequest setPredicate:predicate];
  [fetchRequest setEntity:entity];
  </code></pre>
  
  <p>Can any one help me to resolve this issue.</p>