Skip to content

Document Relationships

A key concept in Formbird is that documents can be 'related' to one another. We've already seen this in action with how the systemHeader.templateId equals the documentId of the document that created it.

              alt text

This relationship can be established by components, by the system or by user coded 'rulesets'.
At this point, we'll discuss the concept and in another topic show examples of how the relationship is established.

              alt text

In the above document you can see that a relationship in Formbird can:

  • be between 2 documents eg: I have a single relationship with my Mother.
  • be between more than 2 documents eg: I have a relationship with my sister and my brother
  • inherit relationships from other relationships - I have a friend named 'Jeff' and he has two friends named 'John' and 'Sally'

Relationships are generally described as objects in an array. At a minimum, the object receives the systemHeader.summaryName and documentId from the related document.

 "responsibleWorkshop": [
        {
            "documentId": "89250990-8de2-11e6-bd66-39c964c02667",
            "name": "Radical Racers"
        }
    ],

It's also possible to bring back any of the data from the related document and write it into the same object.

 "assetDetail": [
        {
            "documentId": "6b817270-8e8c-11e6-bd76-39c864c02667",
            "name": "Passenger Vehicle Hatchback FRT 432",
            "criticalAsset": true,
            "responsibleWorkshop": [
                {
                    "name": "Radical Racers",
                    "documentId": "89250990-8de2-11e6-bd76-39c964c02667",
                    "notify": [
                        {
                            "name": "Fred Mechanic",
                            "documentId": "5435d78388968497030106d0",
                            "email": "fred@radicalracers.com.au"
                        },
                        {
                            "name": "Joe Supervisor",
                            "documentId": "d9f307b0-809e-11e6-af54-4f9e297460c5",
                            "email": "joe@radicalracers.com.au"
                        }
                    ]
                }
            ],
            "primaryMeter": 44674
        }
    ],

It's also possible to write it to the root of the document which can be desirable in certain circumstances.

A point to note, the relationships are not necessarily dynamic. Once saved changes to the related document are not reflected on the document with the saved data unless scripted.
So in this example, if Sally decided not to be friends with Jeff, unless I updated my friends then I would still have Sally as a friend.