NSBatchDeleteRequest deletes all child entities

问题内容:

My CoreData model got two child entities “CarA” and “CarB” with the same abstract parent entity “Car”.

I’m trying to delete all CarA objects using

    func deleteObjects(entityName: String) {
        let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: entityName)
        let deleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)
        do {
            try context.execute(deleteRequest)
        } catch let error as NSError {
            print(error)
        }
    }

Executing deleteObjects("CarA") results in deleting not only all CarA objects, but also all CarB objects as well.

问题评论:

原文地址:

https://stackoverflow.com/questions/47754019/nsbatchdeleterequest-deletes-all-child-entities

添加评论

友情链接:蝴蝶教程