validate method Null safety

  1. @mustCallSuper
ValidationContext validate(
  1. {Validating forEvent = Validating.insert}
)

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. If validations succeed, the returned context ValidationContext.isValid will be true. Otherwise, it is false and all errors are available in ValidationContext.errors.

This method returns 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 allow Validate annotations to run, e.g.:

    ValidationContext validate({Validating forEvent: Validating.insert}) {
      var context = super(forEvent: forEvent);

      if (a + b > 10) {
        context.addError("a + b > 10");
      }

      return context;
    }

Implementation

@mustCallSuper
ValidationContext validate({Validating forEvent = Validating.insert}) {
  return ManagedValidator.run(this, event: forEvent);
}