I have 2 tables, and would like to INNER JOIN them,
the first table describe the "relationship between group and contact", and the second table is the "detail of the contact"
"relationship between group and contact" has two column with groupId & contactId. and now I would like to get multiple contact detail.
(I understand this is not the native way of using core data, but right now I would like to get this work first, then update core data to proper structure later)
Right now I separate that into two fetches, 1st fetch get an contactId array given a groupId, and 2nd fetch will use that contactId array as predicate to fetch contactDetail.
It's working! however, predicate cannot handle more than 1000, so if I get more, it crashed.
Can one suggest how can I set my predicate? Any comment is appreciated!
Thanks
let appDel : AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate
let moc: NSManagedObjectContext = appDel.managedObjectContext!
let fetchRequest = NSFetchRequest()
//3 - set the correct table
let entity = NSEntityDescription.entityForName("Contact", inManagedObjectContext: moc)
fetchRequest.entity = entity
fetchRequest.fetchBatchSize = 20
// Filter
var strForPredicate = String()
strForPredicate = strForPredicate + "id == nil"
for (var i = 0; i < self.fetchedResult_GroupAndContact.count; i++)
{
strForPredicate = strForPredicate + " OR id == \(self.fetchedResult_GroupAndContact[i].contact_id)"
}
Aucun commentaire:
Enregistrer un commentaire