Saving parent with the relationship in one call in ver 4.0 if I know the child objectId


Lets say I have Table A that has one to one relationship to table B.
If the parent in A does not exist but the child in B exist, I read in one of the topics discussed that this will result in 2 calls

  • Save parent in A
  • Set relationship From A to B through where clause

Now my question is if I know the object ID of the child in B. Can I assign the Object Id in my code in the relational column of the new parent and then save it in A? Will this create the relationship then ?

Hi SnakeEyes

No, you can not do that in single call (via DATA api). As you said you need to do 2 requests.

  • Save parent in A

  • Set relationship From A to B through where clause

But I can propose you use BusinessLogic for creation a new table object with relations in single request.
You have two variants:

  1. EventHandler
  2. API Service

In my opinion EventHandler is better solution for this case

  1. create a new EventHandler “beforeCreate<YourTable_A>”
  2. in code of the eventHandler you will create a new object of YourTable_A and assign relations from YourTable_B
  3. return to the client side what you want (YourTable_A with relations)

Take a look at the video which should help you how to create a new EventHandler

Regards Vlad

Hi Vladimir,

Thank you. Hmm thats an interesting feature to check. I like your proposal. I will look into that option