title: core data subquery
body: <p>I have an an entity containing two optional to-many relationships (childA &lt;&lt;-> parent &lt;->> childB).  Each of these two child entities contain an optional string that I am interested in querying on.  </p>
  
  <p>Using the same format, I get the results I expect for one, but not the other.  I understand that means I don't understand the tools I'm working with; and hoped for some insight.  This is what the two queries look like:</p>
  
  <pre><code>childA.@count != 0 AND (0 == SUBQUERY(childA, $a, $a.string != NIL).@count)
  childB.@count != 0 AND (0 == SUBQUERY(childB, $a, $a.string != NIL).@count)
  </code></pre>
  
  <p>I would expect to get back results from non-nil instances of both childA and childB only if each entity instances' string is also nil.  My question is, why would one give the results that I expect; while the other does not?</p>
  
  <p>Clarification:
  I'm trying to solve the general problem where I'm searching for one of two things.  I'm either searching for a default value in an attribute.  When the attribute is optional, I'm additionally searching for a nil attribute.  The problem is further compounded when optional relationships' should only be considered when the are populated.  Without the relationship count != 0, I get back all parents with a nil relationship.  In one case, this is the desired behavior.  In another case, this appears to diminish the returned parent count (to 0 results).  </p>
  
  <p>For the optional attribute case, the query might look like:</p>
  
  <pre><code>parent.@count != 0 AND (parent.gender == -1) OR (parent.gender == NIL)
  </code></pre>
  
  <p>Where there are optional relationships in the key-paths, the query takes the form exemplified in the first example.  </p>
  
  <p>Again, I have gotten the results I have expected with all but one case, where there doesn't seem to be anything unique to it's relationships nor attribute characteristics.  Or I should say, there's nothing unique about this exception in data model structure or query format...</p>