Setting a relationship on save

I am now trying to get to grips with the relationship API. Is there a way to add the relationship at the same time as saving the policy?

I have tried just sending the related objectid to the name of the relationship column but with no success.

i.e. an order exists and I want to add a product to it, how do I insert the product into the order_products table and set the relationship to the order in one single post to the API?

Many Thanks

Hello @Luke_Barlow

At the moment, in order to set/add relations, before doing this, it is necessary that the parent and child objects have already been created. At the same time, you cannot create a parent object, create a child object, and set/add relations between them.

But very soon it can be done with Backendless Transaction - https://backendless.com/docs/js/data_transactions_overview.html

Thanks Vladamir,

So with the current functionality, how would you ensure that when creating the product belonging to the order, it doesn’t become orphaned due to a lost connection between calls to the API?

Luke

Please describe in more detail what you mean, if possible with a small example.

Tell me if I understood you correctly:

  1. A parent object is created.
  2. A child object/objects is created.
  3. Set relations between parent and child objects.
    The question is what will happen if the third point does not work?
  1. The parent object already exists.
  2. I create a child object with a call to the API,
  3. I send a call to the api to link the child with the parent.

what happens if the connection drops between 2 and 3, and therefore 3 is not called? Do I end up with a child with no link to a parent.

thanks

See Set Relation with objects - Return Value

Return Value
Number of child objects set into the relation.

If the connection drops or something went wrong - you will be know about this and try again.

I agree, in this case, the transaction is very good. They will be available to you very soon.