Creating and deleting object hierarchies
Let's assume you want to create grandfather, father and grandchild in a "Person" entity. To fill the "Father" property for the grandchild, you need the DataId of the father record. You can now first save the father using a Save, use the returned GUID to create the father with the next Save call, and so on.
In one step, you do this using a SaveAll: If no entry with the DataId passed in as a parameter exists yet, a new record is created! This also works to create a dependent record in this one query!
Example:
Entity "Person" with the EntityId ff5f6566-d02c-4040-9016-cd222aaff0ee has a property Custom_001 name and a property Custom_002 father. For the sake of clarity, we store the relationship as text in the names.
We use random, newly generated values as DataIds. This works in various programming languages, for example, like this:
C#: Guid.NewGuid(); Java: UUID newGuid = java.util.UUID.randomUUID(); PHP: $newGuid = uniqid(); TypeScript: const newGuid = uuidv4();
{
"items": [
{
"EntityId": "ff5f6566-d02c-4040-9016-cd222aaff0ee",
"DataId": "af92a7a0-e6a2-4237-a33c-5a87dd444fad"
"Custom_001": "Großvater"
}
,{
"EntityId": "ff5f6566-d02c-4040-9016-cd222aaff0ee",
"DataId": "4e609b9b-37c4-43aa-86ce-67e8377e8afa"
"Custom_001": "Vater",
"Custom_002": "af92a7a0-e6a2-4237-a33c-5a87dd444fad",
}
,{
"EntityId": "ff5f6566-d02c-4040-9016-cd222aaff0ee",
"DataId": "af92a7a0-e6a2-4237-a33c-5a87dd444fad"
"Custom_001": "Enkel",
"Custom_002": "4e609b9b-37c4-43aa-86ce-67e8377e8afa"
}
]
}This entire hierarchy can also be deleted using a SaveAll, in which all entries are set to "isActive" = 0. The presence of a "child" may prevent the deletion of a "father". In this case, the order of the records must be reversed: the child is at the top, the grandfather at the bottom:
{
"items": [
{
"EntityId": "ff5f6566-d02c-4040-9016-cd222aaff0ee",
"DataId": "af92a7a0-e6a2-4237-a33c-5a87dd444fad"
"IsActive": 0,
},
{
"EntityId": "ff5f6566-d02c-4040-9016-cd222aaff0ee",
"DataId": "4e609b9b-37c4-43aa-86ce-67e8377e8afa"
"IsActive": 0,
},
{
"EntityId": "ff5f6566-d02c-4040-9016-cd222aaff0ee",
"DataId": "af92a7a0-e6a2-4237-a33c-5a87dd444fad"
"IsActive": 0,
}
]
}