Function Property

  • Model field decorator factory. Using this decorator, Models can be enriched with primitive fields. The compatible primitives are the subset of primitives JavaScript shares with JSON, i.e., Boolean, Date (serialized), Number and String. Objects cannot be uses as a typeFactory argument value, as Model fields containing objects should be declared by the HasOne and HasMany decorators. By employing this decorator, the decorated field will (depending on the transient argument value) be taken into account when serializing or treemapping the Model containing the decorated field.

    Type Parameters

    • T extends Property

      The field value constructor type.

    Parameters

    • typeFactory: (() => T)

      A forward reference to the field value constructor.

        • (): T
        • Returns T

    • transient: boolean = false

      Whether the decorated field is transient.

    Returns (<M>(model, field) => void)

    A Model field decorator.

      • <M>(model, field): void
      • Type Parameters

        Parameters

        Returns void

    Example

    Model with a primitive field:

    import { Model, Property } from '@sgrud/data';

    export class ExampleModel extends Model<ExampleModel> {

    ⁠@Property(() => String)
    public field?: string;

    protected [Symbol.toStringTag]: string = 'ExampleModel';

    }

    See

Generated using TypeDoc