Hello
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 ?
Thanks
Hi SnakeEyes
No, you can not do that in single call (via DATA api). As you said you need to do 2 requests.
But I can propose you use BusinessLogic for creation a new table object with relations in single request.
You have two variants:
- EventHandler
- API Service
In my opinion EventHandler is better solution for this case
- create a new EventHandler “beforeCreate<YourTable_A>”
- in code of the eventHandler you will create a new object of YourTable_A and assign relations from YourTable_B
- 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
https://www.youtube.com/watch?v=XTOgPTTDo3U
Regards Vlad
Hi Vladimir,
Thank you. Hmm thats an interesting feature to check. I like your proposal. I will look into that option