How do the current and previous values behave when adding and removing a row?
The previous value can be taken from the variable $#onfv
and through the reference #old.field_name
.
When adding a row — the previous value is empty! Because the row did not exist.
When deleting a row — the current value is empty! Because the row no longer exists.
Therefore, if you want to perform an action on the delete trigger and use the value from the field of the deleted row, you need to take the previous value (the one that was before the deletion).
Code for the delete trigger action:
=: recalculate(table: 'table'; where: 'connect_field' = $#onfv)
How can I allow an action only when one field value changes from one value to another?
For example, you have statuses [1,2,3,4]
and you need to perform an action only if the status changes from 3
to 4
:
Action code:
=: if(condition: $#onfv = 3; condition: $#nfv = 4; then: $action)
action: set(table: 'table'; field: 'field' = "complete"; where: 'num' = $#nci)
What value should we use if we want to perform an action using the data of the row to be deleted?
Previous value!
=: recalculate(table: 'table'; where: 'connect_field' = $#onfv)