validate method

bool validate ({ValidateOperation forOperation: ValidateOperation.insert, List<String> collectErrorsIn })

Validates an object according to its property Validate metadata.

This method is invoked by Query when inserting or updating an instance of this type. By default, this method runs all of the Validate metadata for each property of this instance's persistent type. See Validate for more information.

This method return the result of ManagedValidator.run. You may override this method to provide additional validation prior to insertion or deletion. If you override this method, you must invoke the super implementation to validate property Validate metadata, e.g.:

    bool validate({ValidateOperation forOperation: ValidateOperation.insert, List<String> collectErrorsIn}) {
      var valid = super(forOperation: forOperation, collectErrorsIn: collectErrorsIn);

      if (a + b > 10) {
        valid = false;
        collectErrorsIn.add("a + b > 10");
      }

      return valid;
    }

collectErrorsIn is guaranteed to be a non-null List when this method is invoked by Query.updateOne, Query.update and Query.insert. It is not guaranteed to be non-null when invoked manually. This list is provided as a reference value by the object performing the validation. Do not create a new List and pass it to the superclass' implementation, as it will not be the same list the caller has access to.

Implementation

bool validate(
    {ValidateOperation forOperation: ValidateOperation.insert,
    List<String> collectErrorsIn}) {
  return ManagedValidator.run(this,
      operation: forOperation, errors: collectErrorsIn);
}