Nested Inserts (Joins)
Last updated
Last updated
While inserts traditionally target a single table, QueryDeck allows you to create related records in nested structures, effectively simulating joins during data insertion. This approach is particularly useful for maintaining parent-child relationships, such as creating a customer and their associated rental records in a single request.
When inserting data with relationships, you can use nested objects to represent the joined tables.
First, select the 'join' button on the left side pane
in the pop that appears, choose tables to join to the selected parent table (here we have chosen rental and payment tables) and close the pop up.
next copy the URL of the endpoint to test by clicking on the top right area
Save the created endpoint, by clicking on "save"
Open postman, choose the method as post and paste the url in the input bar
Then click on body, choose type as raw(json), and use the request body, required as per your need. Here we are using the following body to insert a customer with rentals and payments informations
Request Body:
customer
: Represents the parent table.
rental
: Represents the child table, included as a nested array.
payment
: Represents the grandchild table, nested under rental
.
This structure ensures that all related records are inserted in a single operation, preserving the relationships between the tables.
Now click on send near the input bar the send the request
You should get the following response