prop decorator util is used to define the properties of the model. If needed, multiple prop decorators can be used on the same property.
For usage examples check out the defining models guide.
It supports the following methods:
Just a regular property without any default value
public name: string;
Defines the ID attribute of the model. If the decorator is not used on a model, the default ID attribute will be
public key: number;.identifier
Defines the type attribute of the model. If not used, the type will default to the static type property. This decorator is mostly for internal use and dynamic model types.
public type: string;.type
Used to set a default value of the property.
Note: This needs to be used instead of property assignment. Because of the execution order, property assignment will also override the initial values when creating a model.
true) public favorite: boolean;.defaultValue(
Used to define a reference to one model. Note: The value can also be undefined.
public spouse?: Person;.toOne(Person)
Used to define a reference to multiple models. This decorator is useful because it supports indirect reference (the second argument).
'owner') public children: Array<Person>;.toMany(Person,
Defines a relationship to a single or multiple models. The value can also be undefined.
public pets?: Pet|Array<Pet>;.toOneOrMany(Pet)
prop without decorators
In some cases, you might not be able to use the
@prop decorator, but you can still use it as a function. The function has two arguments: the class you're decorating and name of the property you're decorating. You can find the example in the defining models section.