4 ms·
It's ok to have invalid object as long as you have a final validated state to declare the object as clean. For a model object, I usually run several passes ove
by ww520 11y ago
It's ok to have invalid object as long as you have a final validated state to declare the object as clean.
For a model object, I usually run several passes over its fields after the fields have been populated.
1. Run simple field transformers for individual field (e.g. toUpper, UUID generation, Modified time, Trim, CleanseChars, DeleteChars, Max, Min, Default, etc).
2. Run compound field transformers on related fields (e.g. concat two fields into another one, extract data from another field, compute percentage from another field, etc).
3. Run validation rules on each field.
The validation is run at the end so that it can check the derived fields after transformation.
Validation has a target profile: ForCreate, ForUpdate, ForLoad, etc. Only the target relevant valuation rules defined on the fields are run. E.g. ForCreate profile doesn't check the Required validation rule on the auto generated ID field since the ID will be generated in the database.