Support Topics Documentation Slack YouTube Blog

Transaction API 1:N

Hello,

How to do one to many operations in Transaction API. For example.

I have have a record in table A: A.1. And I create the object for A.1, and need to set the relation in Table B with 2 records : B.1 and B.2. How could I do that in 1 unit of work?

Hello @Michael_Iverson

here is a doc for adding relations using Transactions API https://backendless.com/docs/ios/data_transactions_adding_to_a_relation.html

Regards, Vlad

Let me clarify. Can I set 2 or more relations perunit of work between recods from two different tables.

yes, you can

Even if the Object has 2 parent objects? I don’t see the parameters supporting that. That is what I need to be able to add 2 parent object relations

Hello @Michael_Iverson

If I understand you correctly, then you want to set two parents for one child object, right?
For example:
TableParent 1:N to TableChildren. Objects parent1 and parent2
TableChildren. Object child1

One UnitOfWork, but 2 operations like:

let unitOfWork = UnitOfWork()

unitOfWorkInstance.setRelation( TableParent, parent1, relationColumnName, child1 ) -> OpResult
unitOfWorkInstance.setRelation( TableParent, parent2, relationColumnName, child1 ) -> OpResult

unitOfWork.execute(responseHandler: { (response: UnitOfWorkResult) in
    // Transaction completed. Check the response object if it is a success.
}, errorHandler: { fault in
    // Server reported an error.
})

Is the above the solution? But yes you are correct in your assumption. I want to set to parent relations to a single chiled object in one unit of work.

Hi @Michael_Iverson,

Yes. Have you tried it already? Let us know if you have any further questions.

Regards,
Stanislaw