Function HasMany

  • Model field decorator factory. Using this decorator, Models can be enriched with one-to-many associations to other Models. The value for the typeFactory argument has to be another Model. By applying 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

    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 one-to-many association:

    import { HasMany, Model } from '@sgrud/data';
    import { OwnedModel } from './owned-model';

    export class ExampleModel extends Model<ExampleModel> {

    ⁠@HasMany(() => OwnedModel)
    public field?: OwnedModel[];

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

    }

    See

Generated using TypeDoc