Represents a field in an instance of the BaseEntity class. This class is used to store the value of the field, dirty state, as well as other run-time information about the field. The class encapsulates the underlying field metadata and exposes some of the more commonly used properties from the entity field metadata.

Constructors

Properties

_NeverSet: boolean = true
_OldValue: any
_Value: any
_assertActiveStatusRequired: boolean = false

Indicates whether the active status of the field should be asserted when accessing or setting the value. Starts off as false and turns to true after contructor is done doing all its setup work. Internally, this can be temporarily turned off to allow for legacy fields to be created without asserting the active status.

_entityFieldInfo: EntityFieldInfo
SQLTypeValueRanges: {
    bigint: {
        max: number;
        min: number;
    };
    decimal: {
        max: number;
        min: number;
    };
    float: {
        max: number;
        min: number;
    };
    int: {
        max: number;
        min: number;
    };
    money: {
        max: number;
        min: number;
    };
    numeric: {
        max: number;
        min: number;
    };
    real: {
        max: number;
        min: number;
    };
    smallint: {
        max: number;
        min: number;
    };
    tinyint: {
        max: number;
        min: number;
    };
} = ...

Static object containing the value ranges for various SQL number types. This is used to validate the value of the field when it is set or validated.

Type declaration

  • bigint: {
        max: number;
        min: number;
    }
    • max: number
    • min: number
  • decimal: {
        max: number;
        min: number;
    }
    • max: number
    • min: number
  • float: {
        max: number;
        min: number;
    }
    • max: number
    • min: number
  • int: {
        max: number;
        min: number;
    }
    • max: number
    • min: number
  • money: {
        max: number;
        min: number;
    }
    • max: number
    • min: number
  • numeric: {
        max: number;
        min: number;
    }
    • max: number
    • min: number
  • real: {
        max: number;
        min: number;
    }
    • max: number
    • min: number
  • smallint: {
        max: number;
        min: number;
    }
    • max: number
    • min: number
  • tinyint: {
        max: number;
        min: number;
    }
    • max: number
    • min: number

Accessors

  • get ActiveStatusAssertions(): boolean
  • This property temporarily will set the active status assertions for this particular instance of EntityField. It is temporary because other behaviors in the class instance could reset this value for example calling ResetOldValue() or another caller setting this property to another value.

    Returns boolean

  • set ActiveStatusAssertions(value): void
  • Parameters

    • value: boolean

    Returns void

  • get Dirty(): boolean
  • Returns true if the field is dirty, false otherwise. A field is considered dirty if the value is different from the old value. If the field is read only, it is never dirty.

    Returns boolean

  • get OldValue(): any
  • Returns the old value of the field. This is the value that was set when the field was last loaded from the database.

    Returns any

  • get Value(): any
  • Returns the current value of the field.

    Returns any

  • set Value(value): void
  • Sets the value of the field. If the field is read only, nothing happens. If the field is not read only, the value is set and the internal representation of the dirty flag is flipped if the value is different from the old value.

    Parameters

    • value: any

    Returns void

Methods

  • Convenience method to format the value of the field. This method calls the static method on EntityFieldInfo to do the actual formatting.

    Parameters

    • decimals: number = 2
    • currency: string = 'USD'

    Returns string

  • Resets the NeverSet flag - this is generally an internal method but is available when working with read only fields (mainly primary key fields) to allow them to be set/changed once after the object is created. This is useful for scenarios where you want to set a read only field after the object is created, but only once. This is typically used in the BaseEntity class when loading an entity from an array of values or the DB and reusing an existing object.

    Returns void

  • This method will set the internal Old Value which is used to track dirty state, to the current value of the field. This effectively resets the dirty state of the field to false. Use this method sparingly.

    Returns void

  • Validates the current value of the field. If the field is read only, or if the field is marked to skip validation, nothing happens. If the field is not read only, and the field is not marked to skip validation, the value is checked against the validation rules defined in the metadata for the field.

    Returns ValidationResult

  • Helper method to convert a value to boolean for comparison purposes. Treats truthy values as true regardless of data type.

    Parameters

    • value: any

    Returns boolean