Skip to content

Update with Adding a Relation

The Deep Save API can be used to update an existing object and set a relation with a new child (or parent). Consider the examples below:

Existing Parent and New Child

This example retrieves an existing parent object (Order) and uses the Deep Save API to perform the following:

  1. Save new child object (OrderItem)
  2. Establish relationship between the Order and the new OrderItem.

The Order object already has two related OrderItem objects before the sample code below runs:

order-with-relations

Important

When working with relationships, the Deep Save API applies the "accumulation" policy. This means the following: if a parent object in the database already has some related objects and you update the object with new child objects in the relation, these objects will be added to the relation.

After the code runs, the new OrderItem object is saved in the database and the Order object relation is expanded to include it:

order-with-relations-after-deepsave

Codeless Reference

data_api_deep_save_1

where:

Argument                Description
table name Specify the name of the data table where you want to update an existing record.
object An object to update in the database. Object properties must match the names of the table columns.
return result Optional parameter. When this box is checked, the operation returns the updated object.

The Deep Save API can be used to update an existing object and set a relation with a new child (or parent).

Returns the updated object.

Consider the structure of the data table called Order. This table contains two columns: customer and orderItems. Values in the first column are associated with the Customer data table where the customer names are stored, while values in the second column are related to the OrderItem data table where order details are stored.

data_service_update_with_adding_relation_1

Below you can find the structure of the OrderItem data table where order information is stored.

data_service_update_with_adding_relation_2

The example below updates the related data table called OrderItem by adding a new object to the Order data table.

data_service_update_with_adding_relation_4

After the Codeless logic runs, the new object gets saved to the OrderItem data table.

data_service_update_with_adding_relation_5

The result of this operation will look as shown below after the Codeless logic runs:

data_service_update_with_adding_relation_6