Relation Actions
Actions for changes to relations: a relation moved to another declaring class, a relation removed, or a relation reversed. How upgrades are declared, ordered and run is described in the overview; this page covers the actions themselves.
Naming a relation
An action names the relation as it is stored, which is how it looks in the old model:
{ "from": "commons.dossier", "to": "rulebooks.businessUnit" }
from: the class that declares the relation. A relation is stored under the class that declares it, also when its target is reached through a role.to: the target class of the relation (a relation is identified by its class, see Relations).
A relation added to a class through an EXTENSION is stored under the class the extension extends. The relations that rulebooks.dossier (EXTENSION of commons.dossier) declared are therefore named with "from": "commons.dossier".
Naming a class the new model no longer has is normal here (the old declaring class may be gone), but see "Classes outside the model" under How actions run: when the class is missing from the tenant's model, the action is skipped.
An action that changes a relation states only what changes in becomes: from, to, or both. Whatever you leave out stays as it was.
Actions
| Action | Parameters | Effect |
|---|---|---|
MOVE_RELATION | relation, becomes, when | Re-keys the stored relation to another declaring class, another target class, or both. |
REMOVE_RELATION | relation, when | Removes the stored relation. |
REVERSE_RELATION | relation, multiple, becomes, when | Stores the link on the other side: each target gets the source added to its relation, and the source loses its relation. |
All actions accept an optional when. relation is always required.
MOVE_RELATION
becomes must change something (a from, a to, or both), and the relation it leaves behind must be declared in the new model: the platform checks that the class named by becomes declares a relation to the resulting target class. Single or multiple stays as stored.
Linked objects receive the classes the new relation implies, as when you make the link through the API: moving shareRelation → entity to shareRelation → shareholder makes every linked entity a shareholder; a new from class is added to the object that holds the link. Only the named class is added. Its ancestors are added when the computed values are recalculated afterwards.
REMOVE_RELATION
Drops the links stored under the named relation, for objects that do not need them any more.
REVERSE_RELATION
Moves the link to the other side. rulebooks.businessUnit had a multiple relation to its persons; now a person picks its business units:
{
"action": "REVERSE_RELATION",
"relation": { "from": "rulebooks.businessUnit", "to": "commons.person" },
"multiple": true
}
For a business unit with persons A and B this adds the unit to the businessUnit relation of A and of B, and removes the persons from the unit.
-
multipleis required. The action works on stored data and cannot ask the model whether the new side is single or multiple, so you say it. -
becomesdefaults to the reversed pair: here{ "from": "commons.person", "to": "rulebooks.businessUnit" }. That is only right when the old target class itself declares the new relation:commons.person, or an EXTENSION of it (an extension's relations are stored under the class it extends). -
When the old target is a role, the default is wrong. Suppose the old relation was
rulebooks.businessUnit → rulebooks.businessUnitMember, a role of person. The reversed pair isbusinessUnitMember → businessUnit, but the model declares the new relation on an EXTENSION ofcommons.person, so the link must be stored undercommons.person. Givebecomes:{
"action": "REVERSE_RELATION",
"relation": { "from": "rulebooks.businessUnit", "to": "rulebooks.businessUnitMember" },
"multiple": true,
"becomes": { "from": "commons.person" }
}Without it the action names a class that is no longer in the model, and is skipped for the tenant (an informational notice, no error). The links stay where they were, and a later upgrade that removes the role then drops them. Once the role is no longer referenced, also remove it with
REMOVE_CLASS. -
The
whenis evaluated on the old source object, the business unit. -
When the new side is single and a person already has another unit, the person keeps the one it had, and the conflict is reported.
In the first upgrade of the complete example, the dossiers that are rulebooks keep their relations under the new declaring class (the moves), and the removes drop them from every other dossier, where the relation no longer exists in the model.
Complete example
Two upgrades for the same namespace: the first repairs a moved relation, the second reverses the persons relation together with a model change.
{
"version": 1,
"class": "rulebooks.upgrades",
"kind": "CONFIG",
"dataUpgrades": [
{
"version": 1,
"description": "Relations of commons.dossier moved to rulebooks.rulebook",
"actions": [
{
"action": "MOVE_RELATION",
"when": { "class": "rulebooks.rulebook" },
"relation": { "from": "commons.dossier", "to": "rulebooks.businessUnit" },
"becomes": { "from": "rulebooks.rulebook" }
},
{
"action": "MOVE_RELATION",
"when": { "class": "rulebooks.rulebook" },
"relation": { "from": "commons.dossier", "to": "commons.country" },
"becomes": { "from": "rulebooks.rulebook" }
},
{
"action": "REMOVE_RELATION",
"relation": { "from": "commons.dossier", "to": "rulebooks.businessUnit" }
},
{
"action": "REMOVE_RELATION",
"relation": { "from": "commons.dossier", "to": "commons.country" }
}
]
},
{
"version": 2,
"description": "Business units are now chosen on the person instead of listing their persons",
"actions": [
{
"action": "REVERSE_RELATION",
"relation": { "from": "rulebooks.businessUnit", "to": "commons.person" },
"multiple": true
}
]
}
]
}