Skip to content

Decorators

Michael Dostál edited this page Nov 14, 2018 · 3 revisions

Model decorators

Attributes
  • Attribute(options: AttributeDecoratorOptions)

    • AttributeDecoratorOptions:

      • converter, optional, must implement PropertyConverter interface
      • serializedName, optional
  • NestedAttribute(options: AttributeDecoratorOptions)

    • Nested Attributes can be user for complex attributes:

      • Array of simple typed values [1,2,3]
      • Array of complex values [{firstName:'Peter',...},...]
      • Complex object {firstName:'John', lastName:'Hancock',...}
    • AttributeDecoratorOptions:

      • converter, optional, must implement PropertyConverter interface
      • serializedName, optional
    • NOTE: when using NestedAttribute you always need to specify JsonModelConverter

      • Example:
                   //Array of simple typed values (string, number....)
                   @NestedAttribute({converter: new JsonModelConverter(Array,{hasMany:true})}
                   emails: Array<string>;

                   //Array of complex values
                   @NestedAttribute({converter: new JsonModelConverter(Item,{hasMany:true})}
                   items: Array<Item>;

                   //Complex value
                   @NestedAttribute({converter: new JsonModelConverter(Item)}
                   item: Item;
Relationships
  • BelongsTo()
  • HasMany()

Nested model decorators

Attributes
  • JsonAttribute(options: AttributeDecoratorOptions)

    • AttributeDecoratorOptions:

      • converter, optional, must implement PropertyConverter interface
      • serializedName, optional
Clone this wiki locally