-
Notifications
You must be signed in to change notification settings - Fork 1
HasOne
Mihael Safaric edited this page Apr 25, 2023
·
8 revisions
HasOne is used for decorating model properties which are related to another model. It takes one argument, HasOneOptions, the type and the default values can be checked here.
-
propertyClass:string | ModelConstructor<any> | ModelConstructorFn<any>- required
- possible values: any class or a string representing the model (see DefiningModelRelationships)
- when creating a relationship model, value of this property will be used for creating relationship class instances
-
includeInPayload:boolean- optional
- if true, relationship link will be sent in
POST/PUTrequests
-
externalName:string- if your model property name and the property name fetched from the server are different, you can specify the external property name setting this property
- this name will be used when parsing a response from server and also when generating a payload for sending it to the server
import { HalModel, ModelConfig } from 'ngx-hal';
export class User extends HalModel {
@HasOne()
car: Car;
@HasOne({
propertyClass: CustomAddress
})
address: Address;
}In the example above, car property will contain an instance of Car class. address property will contain an instance of CustomAddress class.
class CustomAddress extends SimpleHalModel {}