I am trying to import high amounts of data and was suggested to use BatchInsert to efficiently import data. With the below code, I was able to import large volumes of data, however, the relationships are not updated. Did some little digging and found out that it is a constraint of BatchInsert. Wanted to confirm if this is true and do I need to write another function that reads the dictionary data and update the inserted records in the second pass.
Below is the code to insert in core data that does not update relationships.
let taskContext = CoreDataStack.shared.mainContext
taskContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
let batchInsertRequest = NSBatchInsertRequest(entityName: entityName.rawValue, objects: data)
if let fetchResult = try? taskContext.execute(batchInsertRequest), let batchInsertResult = fetchResult as? NSBatchInsertResult, let success = batchInsertResult.result as? Bool, success {
return
}
Please review the above code and suggest if I am making any mistake due to which the relationships are not updated. Thank you.