title: Querying for all objects of multiple child entity types in Core Data
body: <p>Given the following contrived example:</p>
  
  <p><img src="https://i.stack.imgur.com/d6BVX.png" alt="Core Data entity diagram for my Awesome Pet Shop App (patent pending)"></p>
  
  <p>I would like to query my data for all objects that are either cats or dogs. I want the result set ordered by name regardless of species, so fetching all cats then fetching all dogs won't do. I want to do this in a single query.</p>
  
  <p>One way to do this would be to add a petType field to Pet, give every record a petType value that identifies the sub-entity it belongs to, then query like so:</p>
  
  <pre><code>NSEntityDescription *entity = [NSEntityDescription entityForName:@"Pet" 
                                            inManagedObjectContext:myMOC];
  [fetchRequest setEntity:entity];
  
  // petType values: 1 = dog, 2 = cat, 3 = goldfish. Yuk.
  NSPredicate *p = [NSPredicate predicateWithFormat:@"petType = 1 OR petType = 2"]
  [fetchRequest setPredicate:p];
  
  // etc...
  </code></pre>
  
  <p>But the mere thought of doing it that way makes me shudder. Is there a better way?</p>
  
  <hr>
  
  <p><strong>Update</strong>: Thanks to all those who've replied - there are some really good, well-thought out solutions here and I appreciate all of them.</p>
  
  <p>To give this some context, the real data model is a little more complex than this (aren't they always), but it's pretty well organised. I've designed more than my fair share of data schemas in my time and I'm happy that the entities and their relationships are well considered. This issue has come about because (to extend the already shaky contrived example) the client originally wanted:</p>
  
  <ul>
  <li>a view showing a list of all pets</li>
  <li>a view showing a list of goldfish</li>
  <li>a view showing a list of cats</li>
  <li>a view showing a list of dogs</li>
  </ul>
  
  <p>So far, so good. But they also want a view showing a combined list of all cats and dogs "because little girls like cats and dogs". (Initially it was cats and goldfish, for the same reason.) There isn't really a way to naturally group that subset of the concrete entities; it's really rather arbitrary.</p>
  
  <p>So far, Dave Dribin's "abstract intermediate entity" approach seems like the cleanest solution, although in my case I think it would feel somewhat artificial; really the only way you could truthfully label the intermediate entity would be as "ThingLittleGirlsLike"! :)</p>