I am trying to use NSBatchUpdateRequest to update a one-to-many relationship.
My entity, Presentation, has multiple Slide, which is another entity, and they have an inverse relationship.
When I try to update slides, I get this error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid relationship ((), name slides, isOptional 1, isTransient 0, entity Presentation, renamingIdentifier slides, validation predicates ( ), warnings ( ), versionHashModifier (null) userInfo { }, destination entity Slide, inverseRelationship presentation, minCount 0, maxCount 0, isOrdered 0, deleteRule 1) passed to propertiesToUpdate:'
I've tried to search for this error, but couldn't find any results.
My code:
let entity = NSEntityDescription.entityForName("Presentation", inManagedObjectContext: managedObjectContext)
let batchRequest = NSBatchUpdateRequest(entity: entity!)
batchRequest.resultType = .UpdatedObjectIDsResultType
batchRequest.propertiesToUpdate = ["date_updated": formattedDateUpdated, "slides": presentationSlides]
do {
let batchUpdateResult = try managedObjectContext.executeRequest(batchRequest) as! NSBatchUpdateResult
let objectIds = batchUpdateResult.result as! [NSManagedObjectID]
for objectId in objectIds {
let managedObject = managedObjectContext.objectWithID(objectId)
managedObjectContext.refreshObject(managedObject, mergeChanges: false)
}
} catch {
let updateError = error as NSError
print(updateError)
}
date_updated updated just fine, so I don't think this is the correct way of updating a relationship.
If anyone needs more code, please let me know. Thanks for any help.
NSBatchUpdateRequest
? That will update every Presentation with the newdate_updated
andslides
. Is that what you want? – pbasdf