let uow = UnitOfWork()
let myUser = uow.create(objectToSave: getBEUserProperty())
_ = uow.setRelation(parentObject: Backendless.shared.userService.currentUser!, columnName: kUserPropKey, childrenResult: myUser)
uow.execute(responseHandler: { result in
print("Is transaction successful - \(result.isSuccess)")
print(result.error?.message)
}, errorHandler: { fault in
print("Error: \(fault.message ?? "")")
})
Unable to perform ‘SET_RELATION’ operation due to argument incompatibility. The operation references a result from another ‘CREATE’ operation. The specified result cannot be obtained from this operation (list of objectIds).
if I comment out the set relation uow the transaction succeeds and the object is created
What this means is the setRelation operation expects a collection of objects in the childrenResult argument, however, in your code you’re passing a single object instead a collection of children.
Yes, the proper way is to convert the argument into an array. Could you please check what you get inside of the result object? Specifically, I’d like to see the individual result for the setRelation operation. You can see the structure of the result object documented here: https://backendless.com/docs/ios/data_transactions_about_unitofwork.html#transaction-result
two things came up though
the result has the key “setrelationUsers1”, is that 1 supposed to be there?
two
your link says the class is
public var operationType: OperationType?
// returns the result of the operation. The object type is determined
// by what the operation returned.
public var result: Any?
but the SDK is
public var operationType: OperationType = .CREATE
public var result: Any?
Every operation included in a transaction has its own result. For example, the result of the setRelation operation will be the number of objects set in the relation.
This is what I wanted to see - how many objects were set in the relation.
Unable to perform ‘SET_RELATION’ operation due to argument incompatibility. The operation references a result from another ‘CREATE’ operation. The specified result cannot be obtained from this operation (list of objectIds).
let uow = UnitOfWork()
let myUser = uow.create(objectToSave: getBEUserProperty())
_ = uow.setRelation(parentObject: Backendless.shared.userService.currentUser!, columnName: kUserPropKey, childrenResult: myUser)
uow.execute(responseHandler: { result in
print("Is transaction successful - \(result.isSuccess)")
print(result.error?.message)
// dump(objectIdReference)
}, errorHandler: { fault in
print("Error: \(fault.message ?? "")")
})
This DOES work
let uow = UnitOfWork()
let items = [getBEUserProperty()]
let createOrderItemsResult = uow.bulkCreate(objectsToSave: items)
_ = uow.setRelation(parentObject: Backendless.shared.userService.currentUser!, columnName: kUserPropKey, childrenResult: createOrderItemsResult)
uow.execute(responseHandler: { result in
print("Is transaction successful - \(result.isSuccess)")
// dump(objectIdReference)
}, errorHandler: { fault in
print("Error: \(fault.message ?? "")")
})
I cant get it to work.
I don’t think there is a bug, but believe the functionality is missing to do what im trying to do.
Create a object,
Relate it to a parent on a 1:1 basis
Im just going to use the bulk method and call it good for now