Skip to main content Skip to complementary content

Relational objects in a data synchronization

This article describes different patterns to implement a one-way data sync of relational objects, for example, Companies and Contacts, where contacts (child objects) are linked to a Company (parent objects).

The challenge of data sync with relational is that the parent object must exist in the destination before the child can be created in the destination.

On top of that, the child object must be linked to the parent object in the destination. This link is in many cases done via a Foreign Key, meaning the id of the parent in the destination. This can be a challenge since this id is different from the id in the source.

Example:

  • Source Webshop: Contact A with id 123 is linked to Company B with id 567
  • Destination CRM: Contact A with id 777 must link to Company B with id 888

Example pattern with relational objects - only create child objects

In the following example, we sync Contacts from a Demo Webshop to a Demo CRM. We assume that the parent objects (companies) already exist in the destination Demo CRM. We search for the existing company by VAT number, in order to have its id that we use as Foreign Key.

Syncing contacts to a CRM.

an automation consisting of a List New And Updated Contacts block containing a Get Company By VATNumber block and an Add Or Update Contact block.

When we upsert (create or update) the contact (child object), we use the id (Foreign Key) of the company from the destination:

Acquiring a foreign key.

The Inputs tab of the Add Or Update Contact block. Company Id is set to Get Company By VATNumber > Id, Name is set to List New And Updated Contact... Item > Name, and Email is set to List New And Updated Contact... Item > Email.

Pattern to create child and parent objects

In the following example pattern, we upsert the parent object first, and then use the response from this upsert to have the id of the parent (used as Foreign Key when upserting the child):

Upserting a parent and child object.

an automation consisting of a Start block and a List New And Updated Contacts block containing a Get Company block, an Add Or Update Company block, and an Add Or Update Contact block.

Pattern with lookup in a list for parent objects

Sometimes it's impossible to quickly find the parent object in the destination, for example, because the Get company by VAT number is not available. In that case, we can retrieve a full list of parent objects from the destination, and do lookups to find the Foreign Key. This pattern will only work if the number of parent objects is limited (e.g. thousands of records but not millions of records).

Retrieving parent objects for lookup.

an automation consisting of a Label block, a List Companies block, and a List New And Updated Contacts block containing a Get Company block, a Lookup Item in List block, a Condition block which acceses an Add Or Update Company block, and an Add Or Update Contact block.

Racing conditions - parent object does not exist yet

The following pattern can cause racing conditions. The parent objects are synced first, and then the children are synced. Let's assume the first part (syncing the parent objects) takes 10 minutes, and during this loop, a new parent object is created in the source. This new parent will not yet be part of the loop and will not be created in the destination. When the children are synced, the new parent may be missing in the destination, causing the creation of the child to fail.

Example pattern that may cause racing conditions:

an automation that may cause racing conditions.

an automation consisting of a Label block, a List New And Updated Companies block containing an Add Or Update Company block, and a List New And Updated Contacts block containing an Add Or Update Contact block.

Handling racing conditions on error

The solution is to handle the racing condition (catch the error), and create a parent object when missing:

an automation that prevents racing conditions.

an automation which consists of a Label block, a List New And Updated Companies block containing an Add Or Update Company block, and a List New And Updated Contacts block containing an Add Or Update Contact block and a Condition block which accesses an Add or Update Company block and an Add Or Update Contact block when an error is detected.

Use the error formula to read the error from the block Add or update contact:

Reading an error.

The Inputs tab of the Condition block. It triggers when the Add Or Update Contact block contains and Unknown company.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!