title: swift CoreData predicates to filter all the child data of a given parent
body: <p>There are two entities <code>Child</code> and <code>Parent</code>. <code>Parent</code> and <code>Child</code> is one to many relationship, one <code>Parent</code> with many <code>Child</code>.</p>
  
  <p>The code I referred to is as following and it can filter all the data of <code>Child</code> level whose Attribute <code>text</code> contains <code>yes</code>:</p>
  
  <pre><code>@State private var predicate: NSPredicate? = NSPredicate(format: "text contains[c] %@", "yes")
  @ObservedObject private var db = CoreDataDB&lt;Child&gt;()
  
  for child in self.db.loadDB(predicate: self.predicate):
      ....
  </code></pre>
  
  <p>What I want to do is to get all the <code>Child</code> level's data belong to current <code>Child</code> data's <code>Parent</code>.</p>
  
  <pre><code>var child: Child
  
  // How to write this line???
  @State private var predicate: NSPredicate? = NSPredicate(format: "parent = %@", "self.child.parent")
  
  @ObservedObject private var db = CoreDataDB&lt;Child&gt;()
  
  for child in self.db.loadDB(predicate: self.predicate):
      ....
  </code></pre>
  
  <p>I do not know how to write the <code>predicate</code> above to filter data that belong to the same <code>Parent</code> with current <code>child</code> in current <code>child</code>'s View. </p>
  
  <p><code>NSPredicate(format: "parent = %@", "self.child.parent")</code> will get nothing when <code>for child in self.db.loadDB(predicate: self.predicate):</code>.</p>
  
  <p><code>NSPredicate(format: "child.parent = %@", "self.child.parent")</code> will get error saying <code>keypath child.parent not found in entity &lt;NSSQLEntity Child id=1&gt; with userInfo of (null)</code></p>
  
  <p>What I need to say is that <code>text</code> of <code>Child Entity</code> in the code is an Attribute I created, but <code>parent</code> of <code>Child Entity</code> is auto created by the <code>one to many</code> relationship with <code>Parent Entity</code>. I cannot see <code>parent</code> Attribute in <code>xcdataModelId</code> file but I can use it in the code.</p>
  
  <p>Thanks for any help.</p>