Add as metadata to persistent properties to validate their values before insertion or updating.

When executing update or insert queries, any properties with this metadata will be validated against the condition declared by this instance. Example:

    class Person extends ManagedObject<_Person> implements _Person {}
    class _Person {
      @managedPrimaryKey
      int id;

      @Validate.length(greaterThan: 10)
      String name;
    }

Properties may have more than one metadata of this type. All validations must pass for an insert or update to be valid.

By default, validations occur on update and insert queries. Constructors have arguments for only running a validation on insert or update. See runOnUpdate and runOnInsert.

This class may be subclassed to create custom validations. Subclasses must override validate.

Constructors

Validate({bool onUpdate: true, bool onInsert: true })

Invoke this constructor when creating custom subclasses.

const
Validate.absent({bool onUpdate: true, bool onInsert: true })

A validator for ensuring a property does not have a value when being inserted or updated.

const
Validate.compare({Comparable lessThan, Comparable greaterThan, Comparable equalTo, Comparable greaterThanEqualTo, Comparable lessThanEqualTo, bool onUpdate: true, onInsert: true })

A validator for comparing a value.

const
Validate.length({int lessThan, int greaterThan, int equalTo, int greaterThanEqualTo, int lessThanEqualTo, bool onUpdate: true, onInsert: true })

A validator for validating the length of a String.

const
Validate.matches(String pattern, { bool onUpdate: true, onInsert: true })

A validator for matching an input String against a regular expression.

const
Validate.oneOf(List values, { bool onUpdate: true, bool onInsert: true })

A validator for ensuring a value is one of a set of values.

const
Validate.present({bool onUpdate: true, bool onInsert: true })

A validator for ensuring a property always has a value when being inserted or updated.

const

Properties

runOnInsert → bool

Whether or not this validation is checked on insert queries.

final
runOnUpdate → bool

Whether or not this validation is checked on update queries.

final
hashCode → int

The hash code for this object.

read-only, inherited
runtimeType → Type

A representation of the runtime type of the object.

read-only, inherited

Operators

operator ==(other) → bool

The equality operator.

inherited

Methods

validate(ValidateOperation operation, ManagedAttributeDescription property, T value, List<String> errors) → bool

Custom validations override this method to provide validation behavior.

noSuchMethod(Invocation invocation) → dynamic

Invoked when a non-existent method or property is accessed.

inherited
toString() → String

Returns a string representation of this object.

inherited