Configuring Cascading Deletes
When you delete or anonymize a record in Aam Digital, the system automatically handles related records that reference the deleted record. How each related record is treated depends on the relationship role configured for the reference field.
How It Works
Every field that links to another entity type has a relationship role (entityReferenceRole) that tells the system what should happen to the record containing that link when the referenced record is deleted or anonymized.
There are two roles:
-
"aggregate"(default)The two records exist independently of each other ("has a" relationship).
-
on delete, the reference is removed from the field, but the related record is kept.
-
on anonymize, the related record is kept unchanged.
-
-
"composite"The related record "belongs to" the deleted record and should not exist without it ("part of" relationship).
-
on delete, the related record is also deleted (cascading delete).
-
on anonymize, the related record is also anonymized.
-
If no
entityReferenceRoleis set on a field, it defaults to aggregate — the safe option where records are never automatically deleted.
Example: Survey linked to a Participant
Consider a "Survey" record that captures responses for a specific participant and references the social worker who conducted it:
-
The participant field points to a
Child(participant) and is marked"composite"— a survey response only makes sense as part of that participant's data. If the participant is deleted, the survey is deleted too. -
The conductedBy field points to a
User(the social worker) and is marked"aggregate"— the social worker exists independently. If the social worker is deleted, the survey keeps existing but the reference is cleared.
Configuring via the Admin Entity Configuration
You can set the relationship role in the entity configuration (the "Config" entity in the admin UI or the JSON config files).
In the entity's attributes, add the entityReferenceRole property to any field that references another entity:
{
"entity:Survey": {
"attributes": {
"participant": {
"dataType": "entity",
"additional": "Child",
"entityReferenceRole": "composite",
"label": "Participant"
},
"conductedBy": {
"dataType": "entity",
"additional": "User",
"entityReferenceRole": "aggregate",
"label": "Conducted by"
}
}
}
}
Step by Step
-
Open the Admin section and navigate to the Entity Configuration for the entity type you want to modify (e.g. "ChildSchoolRelation").
-
Find the field that references another entity (its
dataTypewill be"entity"or"entity-array"). -
Set
entityReferenceRoleto one of:-
"composite"— to enable cascading delete/anonymize for this relationship. -
"aggregate"— to only remove the reference when the linked record is deleted (this is the default, so you can also omit it). -
(!) this setting can currently not be made in the Admin UI. It needs to be configured directly in the raw config json document.
-
-
Save the configuration.
When to Use "composite"
Mark a field as "composite" when the record only makes sense in the context of the referenced entity. Typical examples:
-
A survey response that belongs to a specific participant
-
A note or activity record that references participating children
-
A task or to-do that belongs to a specific case
When to Use "aggregate" (or leave the default)
Use "aggregate" (or simply omit the setting) when both records are meaningful on their own. Typical examples:
-
A survey's reference to the social worker who conducted it (the survey still documents the participant's answers even if the social worker record is removed)
-
A record referencing a configurable category or status value
Important Notes
-
Cascading is recursive: If a composite-related record also has composite references to further records, those will be deleted/anonymized too.
-
Undo is available: After a cascading delete, the system offers an undo action that restores all affected records.
-
Only single-composite triggers full cascade: If a related record has multiple composite reference fields but only one of them points to the deleted entity, the cascade applies. If other composite references also exist and still have values, the record is treated as aggregate instead (only the reference is removed).