Please see the below details for data insertion.
I have to insert multiple records on two different tables at same time or optimized way.
Let's assume 2 tables : Table A, Table B.
Table A has 1 to many relationship with Table B.
Table A column : colA1
Table B column : colB1
Input :
[
{ "colA1": "AAA1","colB1":"BBB1" },
{ "colA1": "AAA1","colB1":"BBB2" },
{ "colA1": "AAA2","colB1":"BBB3" },
]
Expected output :
Table A:(parent).
Id | name
1 | AAA1
2 | AAA2
Table B:(child)
Id | Table A id | name
1 | 1 | BB1
2 | 1 | BB2
3 | 2 | BB3
We can achieve the bulk insertion by using insert or createMany methods for single table but i want to insert into two tables for designed relations