-
Notifications
You must be signed in to change notification settings - Fork 1
HasMany
Mihael Safaric edited this page Aug 10, 2022
·
6 revisions
HasMany is used for decorating model properties which consist of multiple other models of the same type. It takes one argument, HasManyOptions, the type and the default values can be checked here.
-
itemsType:string | ModelConstructor<any> | ModelConstructorFn<any>- mandatory
- when:
-
ModelConstructor<any>- it represents a class which is used for creation of new elements
-
ModelConstructorFn<any>- it represents a function which, when executed, returns a class which should be instantiated
-
string- similar to the case with
ModelConstructor<any>, but instead of providing a concreate class, the class will be searched inDatastoreService.modelTypesbased onmodelType(see DefiningModelRelationships)
- similar to the case with
-
-
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 {
@HasMany({
itemsType: Car
})
cars: Array<object>
}In the example above, user.cars will contain an array of Car instances.