Instead of validating alterations (add, modify and delete) on tables at several places in parts of modules that approach these tables, it might be better, in my opinion, to perform these validations in special server actions. Maybe it is even better to create a special module for it that is stacked on the ‘Core’ module. Validations, for a specific alteration on a certain table, are always performed the same way in that case, no matter where the server action is initiated (screen, process …).
Having these special server actions, it is also easy to perform inter table validations. The deletion of a record of table A might result into an update of table B. If the update of the B-record is not allowed due to its validations, the deletion of the A-record may not take place either. This implies that the server action ‘ValidationCreateOrUpdateTableB’ is started within ‘ValidationDeleteTableA’. To instruct the caller, an output parameter should return the result of the validation. So, the outcome might be a description about the validation error or just empty if okay.
Introducing the validation server actions will imply that the database actions ‘CreateOrUpdateTable’, ‘CreateTable’, UpdateTable’ and ‘DeleteTable’ should not be used anywhere outside their validation server actions anymore.
The ‘ValidationCreateOrUpdateTable’ server action should check whether the input Id prameters is empty or not. If empty (nullIdentifier), the ‘ValidateCreateTable’ action should be started. When this action returns an empty value (a correct validation and an insertion), a new Id is returned as well. However, when the action returns an error description, the complete action should be cancelled. If the insertion is correct, but the following update is not correct, an abort transaction should be performed to undo the insertion in that case.
Would the use of validation server actions be an option?
Merged from 'Would the use of validation server actions be an option?' (idea created on 20 Jun 2018 12:17:50 by René Cornet), on 02 Jul 2018 09:57:06 by Fernando MoitinhoThis comment was:
- originally posted on idea 'Entity - Generated "Create Or Update" Entity Actions' (created on 15 Nov 2017 by Miguel Sousa)
- merged to idea 'Allow redefining entity built-in actions' on 08 Aug 2018 03:41:30 by Justin James