title: NSPredicate to get entity of a relationship matching two conditions
body: <p>I am using <code>Core Data</code> to fetch entities. I need to fetch only entities that have a relationship <code>attribute</code> that has the ID of <code>41</code> AND that same <code>attribute</code> needs to have the <code>isOn</code> property set to YES.</p>
  
  <p>Here is what I am trying:</p>
  
  <pre><code>[NSPredicate predicateWithFormat:@"(SELF IN %@ AND ANY attributes.attributeID.intValue == 41) AND (SELF IN %@ AND ALL attributes.isOn == %@)", self.places, self.places, @YES];
  </code></pre>
  
  <p>For some reason this crashes my app with not explanation.</p>
  
  <p>Any ideas on if my predicate format is wrong?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Doing more research it seems I need to use <code>SUBQUERY</code> but not quite sure how in this case. Here is what I tried but it also crashes with a "cannot parse format" error:</p>
  
  <pre><code>[NSPredicate predicateWithFormat:@"SUBQUERY(SELF IN %@, $e, $e.attributes.attributeID.intValue == %i &amp;&amp; $e.attributes.isOn == %@).@count &gt; 0)", self.places, 41, @YES]
  </code></pre>