Our active entity object will also give you access to our validation engine (cbValidation) by giving your ORM entities the following functions:
/** * Validate the ActiveEntity with the coded constraints -> this.constraints, or passed in shared or implicit constraints * The entity must have been populated with data before the validation * * @fields One or more fields to validate on, by default it validates all fields in the constraints. This can be a simple list or an array. * @constraints An optional shared constraints name or an actual structure of constraints to validate on. * @locale An optional locale to use for i18n messages * @excludeFields An optional list of fields to exclude from the validation. */boolean functionisValid( string fields="*", any constraints="", string locale="", string excludeFields=""){/*** Get the validation results object. This will be an empty validation object if isValid() has not being called yet.*/cbvalidation.models.result.IValidationResult functiongetValidationResults(){
Declaring Constraints
This makes it really easy for you to validate your ORM entities in two easy steps:
1) Add your validation constraints to the entity
2) Call the validation methods
Let's see the entity code so you can see the constraints:
Here are the most common methods for retreving the errors from the Result object via the getValidationResults() method:
getResultMetadata()
getFieldErrors( [field] )
getAllErrors( [field] )
getAllErrorsAsJSON( [field] )
getAllErrorsAsStruct( [field] )
getErrorCount( [field] )
hasErrors( [field] )
getErrors()
The API Docs in the module (once installed) will give you the latest information about these methods and arguments.
Unique Property Validation
We have also integrated a UniqueValidator from the validation module into our ORM module. It is mapped into WireBox as UniqueValidator@cborm so you can use it in your model constraints like so: