How to store nested data entities
Introduction
Would you like to save multiple products in your data entities? Then create nested entities in your solution by following these steps.
Prerequisites
- You have a working solution with an
EntityDataStoreand anEntityTable.
1. Add a reference type property
To store nested entities, in the EntityDataStore configuration:
- Define a property with
type: Reference. - Define the
entityTypeto be nested in the “root” entity.. - Define the
defaultvalues in the nested entity.
The configuration should look similar to the example below:
my-entity-datastore:
kind: EntityDataStore
properties:
my-prop-a:
type: Number
my-nested-entities:
type: Reference
entityType: my-nested-entity-prop
default: []
2. Define entityTypes
To configure the properties of the nested entities:
- Define
entityTypesthe “root” entity contains. TheentityTypesdefine the entities that can be nested in the root or other nested entities. - Define the
propertiesof the nested entity.
The configuration should look similar to the example below:
my-entity-datastore:
kind: EntityDataStore
properties:
my-prop-a:
type: Number
my-nested-entities:
type: Reference
entityType: my-nested-entity-prop
default: []
entityTypes:
my-nested-entity-prop:
properties:
my-nested-entity-prop-a:
type: Number
my-nested-entity-prop-b:
type: Number
💡 To nest another entity in a nested entity, define the entityType on the root level, define a Reference property and set the entityType on the nested entity level.
3. Subscribe EntityDataStore to the ControlPanel to add/edit “root” entities
To save the ControlPanel values to an entity on the “root” level in the EntityDataStore:
- Subscribe the
EntityDataStoreto theControlPanel. - Define the
frameandsource. - Set the
actionto be performed.updatefor editing the values of an existing selected entity.insertfor adding a new entity with the defined values.
4. Subscribe EntityDataStore to the ControlPanel to add/edit “nested” entities
To save the ControlPanel values to an entity on the “nested” level in the EntityDataStore:
- Subscribe the
EntityDataStoreto theControlPanel. - Define the
frameandsource. - Set the
actionto be performed.updatefor editing the values of an existing selected nested entity.insertAtfor adding a new nested entity with the defined values.
- Configure the
insertAtaction. Define which level the entity should be inserted. To insert a nested entity, the path is defined by the nested level(s).
my-entity-datastore:
kind: EntityDataStore
subscribe:
- kind: ControlPanel
frame:
source:
action:
type: InsertAt
at: [my-nested-entities]
5. Subscribe the EntityTable to the EntityDataStore
To show the nested entities in a table,
- Subscribe the EntityTable to the EntityDataStore.
- Define the frame and the source.
- Define the path to the nested entity with the pathToBranch property. $root refers to the root entity level. To show a nested entity in the table, the path would be the root level, followed by the nested level(s).
- To show the nested entities in the selected root entity, set
filterBySelected.
my-entity-table:
kind: EntityTable
subscribe:
- kind: EntityDataStore
frame: my-frame
source: my-entity-datastore
pathToBranch: [$root, my-nested-entities]
filterBySelected: [$root]
💡 Afterwards, you can select nested entities in the table by subscribing the EntityDataStore to the EntityTable.
See the image below as an example.
Configuration
See the entity data store configuration docs for more information.