title: Predicate matching one to many relationship coredata
body: <p>I am trying to get the total price of a bill which has many items related to it in coredata. I am struggling to understand the predicate syntax required to retrieve the items so that i can access their prices. I keep getting the following error :</p>
  
  <pre><code>    2016-12-14 14:13:12.309 Splitter[43533:5597917] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'unimplemented SQL generation for predicate : (ANY items IN &lt;Splitter.Bill: 0x7fe6e0cebbd0&gt; (entity: Bill; id: 0xd000000000300000 &lt;x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Bill/p12&gt; ; data: {
      date = "December 14, 2016";
      id = "6D672183-44C2-4961-ABB6-27FD657E5C68";
      items =     (
      "0xd000000001fc0012 &lt;x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Item/p127&gt;",
      "0xd0000000020c0012 &lt;x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Item/p131&gt;",
      "0xd000000002080012 &lt;x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Item/p130&gt;",
      "0xd000000002100012 &lt;x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Item/p132&gt;",
      "0xd000000002040012 &lt;x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Item/p129&gt;",
      "0xd000000001f00012 &lt;x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Item/p124&gt;",
      "0xd000000001f80012 &lt;x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Item/p126&gt;",
      "0xd000000001e80012 &lt;x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Item/p122&gt;",
      "0xd000000001f40012 &lt;x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Item/p125&gt;",
      "0xd000000001ec0012 &lt;x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Item/p123&gt;",
      "(...and 1 more...)"
      );
      location = hgfhgfd;
      name = hgfhgfd;
      total = 0;
      }))'
  </code></pre>
  
  <p>From the following code:</p>
  
  <pre><code>func setBillTotal() {
      let managedContext = billObject.managedObjectContext
      let fetchRequest = NSFetchRequest(entityName: "Item")
      let predicate = NSPredicate(format: "ANY items IN %@", billObject)
      fetchRequest.predicate = predicate
      var items = [Item]()
      do {
          let results =
              try managedContext!.executeFetchRequest(fetchRequest)
          items = results as! [Item]
      } catch let error as NSError {
          print("Could not fetch \(error), \(error.userInfo)")
      }
  
      var sum = Int(0.0)
      for item in items {
          sum += Int(item.price)
      }
  
      billObject.setValue(sum, forKey: "total")
      do {
          try managedContext!.save()
      } catch let error as NSError  {
          print("Could not save \(error), \(error.userInfo)")
      }
  }
  </code></pre>
  
  <p>Database relationship images: <a href="https://i.stack.imgur.com/FRyvz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FRyvz.jpg" alt="Item"></a> <a href="https://i.stack.imgur.com/buUT3.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/buUT3.jpg" alt="Bill"></a></p>
  
  <p>Any help would be great, im sure its a simple fix but the syntax is going over my head somewhere. Thanks</p>