prorm API Reference
    Preparing search index...

    Function Validate

    • Attach validation rules — to one field, or to the whole model.

      On a property the rules are per-column, and run before every insert and update:

      `@Validate`({ isEmail: true, len: [5, 254] })
      declare email: string;

      `@Validate`({ isIn: [['draft', 'live']], msg: 'unknown status' })
      declare status: string;

      On the class the values are functions, called with this bound to the instance — the place for a rule that spans columns, which no per-column rule can express. A validator reports by throwing:

      `@Validate`({
      endsAfterStart() {
      if (this.endsAt <= this.startsAt) throw new Error('endsAt must be after startsAt');
      },
      })
      class Event extends Model {}

      Applying it twice merges, so rules can be split across lines or inherited from a base class.

      Parameters

      • rules: ValidationRules

      Returns PropertyDecorator & ClassDecorator