title: Core Data predicate to filter by a subentity attribute
body: <p>I have been looking for this but I found nothing and I think it's unsupported by Core Data. Anyway, let's see it:</p>
  
  <p>I have 3 entities: <code>Ticket</code>, <code>TicketLine</code> and <code>CheffLine</code>.</p>
  
  <p><img src="https://i.stack.imgur.com/c25E1.png" alt="A Ticket contains multiple TicketLines (Ticket.lines). **CheffLine** inherits from TicketLine."></p>
  
  <p>Now I want to fetch the tickets (by means of a <code>NSFetchedResultsController</code>), but filtering the tickets that have at least one CheffLine with a <code>cheffStatus</code> <strong>greater than 0</strong>. The problem is that <code>cheffStatus</code> is an attribute of the <code>CheffLine</code> entity, so I make this predicate:</p>
  
  <pre><code>[NSPredicate predicateWithFormat:@"0 != SUBQUERY(lines, $x, $x.cheffStatus &gt; 0).@count)"];
  </code></pre>
  
  <p>But when executed, I get this error:</p>
  
  <blockquote>
    <p>Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to generate SQL for predicate (0 != SUBQUERY(lines, $x, $x.cheffStatus > 0).@count) (problem on RHS)'</p>
  </blockquote>
  
  <p>I noticed that if the query is done using <code>$x.someVariableInTheTicketLineEntity</code> instead of <code>$x.cheffStatus</code>, it works. I also tried to use CAST, but obtained the same result</p>
  
  <pre><code>[NSPredicate predicateWithFormat:@"0 != SUBQUERY(lines, $x, CAST($x, 'CheffLine').cheffStatus &gt; 0).@count)"];
  </code></pre>
  
  <p>Is there any way of doing this query? Remember that it must work inside a <code>NSFetchedResultsController</code>.</p>