Child Of Field in Collections
Child of field in collections allows you to bind two fields of different collections in a parent-child relation. When data gets added in the parent field, it automatically gets reflected in the child field as well.
How to add a "Child Of" field?
For detailed explanation, we are using the example of creating a database for customer orders.
1. Create a Parent Collection
The first step is to create required collections that you want to bind in parent-child relation. As per the example we are using, we have created a parent collection named "Customers".
2. Create a Child Collection
Now create a new collection that would be the child collection. As per the example, we have created a child collection named "Orders".
3. Create a Field for Order ID in Child Collection
Add a text field in the Orders collection for adding different order IDs.
4. Create Fields in the Parent Collection
Now add the following fields in the parent collection, "Customers":
Text field: A text field named Customer Name is added in the parent collection, "Customers".
Reference field: A reference field is created in the parent collection in reference with the child collection. In the example below, the reference field is named as "All Orders". It will allow the reference field to automatically get data entered in the Order ID field of the child collection, "Orders".
5. Create a "Child Of" Field in the Child Collection
Now open the child collection and add a "Child Of" field in it.
To successfully create a "Child Of" field, carefully fill all the fields. First, name the field, for example, "Customer" as done in the example below.
Second, select the parent collection whose child is the child collection, for example "Customers" collection.
Third, select the reference field created previously in the parent collection, for example "All Orders" as shown below.
Fourth, select the field that display customers' name.
6. Add Data in the Parent Collection
Now manually add data in the parent collection or dynamically bring data using a collection form. In the example below, we have added a customer named "John Doe".
As you can see in the example below, there is no data in the "All Orders" field.
7. Add Data in the Child Collection
Now manually add data in the parent collection or dynamically bring data using a collection form.
As per the example we've used, an order ID has to be first added. As the second field, "Customer" is a "Child Of" field, it displays the customers created in the parent collection, "Customers", i.e. John Doe.
In the example below, we have added two orders for the customer, John Doe.
8. Open the Parent Collection
Now as you will open the parent collection you will see that data added in the child collection is getting reflected in the parent collection.
In the example below, now customer named John Doe has 2 orders.