Transactions, unitOfWork.create as a child of setRelation

Hi Team,

Hopefully a quick one on transactions.
I’m creating a new object with unitOfWork.create. I want the object created to be used in two setRelation, one as the parent and one as the child.

The first setRelation using the code below works fine (with the created object as the parent).
The second I’m having some trouble with, I appreciate that when setting the children the setRelation is expecting a collection and not a single object. I’ve tried to get around this by attempting to get the objectIdReference using .resolveTo and then putting that in a String array as the children. Unfortunately this doesn’t work.
The second relation does work if I create the newTeamMember with bulkCreate, but then I have issues trying to get it to work with the first setRelation.

Please can you provide guidance on how to best do this in a transaction where the created object needs to be a parent and a child.

UnitOfWork unitOfWork = new UnitOfWork();
Team newTeamMember = new Team();
OpResult addnewTeamMemberResult = unitOfWork.create( newTeamMember );
OpResultValueReference objectIdReference = addnewTeamMemberResult.resolveTo( "objectId" );

unitOfWork.setRelation( addnewTeamMemberResult, "venue", new String[]{venue.getObjectId()} );
unitOfWork.setRelation(venueOwner, "team", new String[]{objectIdReference.getOpResult().getOpResultId()});

Hi. Have you read the documentation ?

In last line of code you need reference not to the transaction operation id (OpResultId), but to the objectId, which is represented by the objectIdReference.

unitOfWork.setRelation(venueOwner, "team", new String[]{objectIdReference});

Hi Oleg,

Unfortunately the objectIdReference isn’t a String but a OpResultValueReference

Hi Reece,

What if you try using addnewTeamMemberResult in the setRelation call instead of objectIdReference ?

Mark

Hi Mark,

You can put the OpResult object there, but unfortunately the function requires that its a collection of children and not a single child so errors out. (If you create newTeamMember with bulkCreate and put that in the setRelation call it works fine)

We’ve checked and for now it works only for REST SDK.
We’ve created the task [BKNDLSS-20876] to add such a possibility for other SDKs.

1 Like

Hi Oleg/Team,

Any joy on looking at BKNDLSS-20876?

Hello @Reece_Smith,

Sorry for inconvenience, the internal ticket for this issue is BKNDLSS-23872 (not BKNDLSS-20876). Ticket status is “open” but our developer will look into it as soon as possible.

Regards,
Olha

Hi Team,

Just checking in on this one, has anyone been able to look @ BKNDLSS-23872

Hi @Reece_Smith

The ticket is currently open. I will increase the priority and our team will try to resolve your issue as soon as possible.

Best Regards,
Maksym

Hi, @Reece_Smith

Sorry, for the long reply. We have updated our cloud servers where added the opportunity to add a unitOfWork object as a child object of setRelation.

The latest maven repository is 6.3.0.

https://mvnrepository.com/artifact/com.backendless/backendless/6.3.0

Please verify whether everything works fine now.

Regards,
Marina