Skip to main content

ModelLink

@webda/models


Class: ModelLink<T>

Defined in: packages/models/src/relations.ts:412

Define a link to n:1 or 1:1 relation on the current model to another model

T is the model to link to

This is expected to be the symetric of ModelRelated or ModelLink in a 1:1 relation

class Album extends Model {
artist: ModelLink<Artist>;
}

Type Parameters​

T​

T extends Storable

Implements​

Constructors​

Constructor​

new ModelLink<T>(model): ModelLink<T>

Defined in: packages/models/src/relations.ts:420

Create a new ModelLink

Parameters​

model​

ModelClass<T>

the model class to link to

Returns​

ModelLink<T>

Properties​

[RelationKey]​

protected [RelationKey]: PrimaryKeyType<T>

Defined in: packages/models/src/relations.ts:414


[RelationModel]​

readonly [RelationModel]: ModelClass<T>

Defined in: packages/models/src/relations.ts:415


[RelationRole]​

readonly [RelationRole]: "Link"

Defined in: packages/models/src/relations.ts:413

Implementation of​

ModelLinker.[RelationRole]

Methods​

get()​

get(): Promise<T>

Defined in: packages/models/src/relations.ts:433

Resolve the link and fetch the target model from the repository

Returns​

Promise<T>

the linked model instance


getPrimaryKey()​

getPrimaryKey(): PrimaryKeyType<T>

Defined in: packages/models/src/relations.ts:481

Get the primary key of the linked model

Returns​

PrimaryKeyType<T>

the primary key value


set()​

set(id): this

Defined in: packages/models/src/relations.ts:446

Update the link to point to a different target

Parameters​

id​

string | T | PrimaryKeyType<T>

New target: a primary key, model instance, or string UID

Returns​

this

this link instance

Webda Auto Setter​


toJSON()​

toJSON(): PrimaryKeyType<T>

Defined in: packages/models/src/relations.ts:470

Serialize the link to its primary key value

Returns​

PrimaryKeyType<T>

the primary key value


toString()​

toString(): string

Defined in: packages/models/src/relations.ts:459

Return the string representation of the linked key

Returns​

string

the string representation