Skip to main content

ModelLink

@webda/models


Class: ModelLink<T>

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

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

Deleting the target does nothing to the model unless the attribute declares @OnDelete <POLICY>

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:443

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:434

[relation key]


[RelationModel]​

readonly [RelationModel]: ModelClass<T>

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

[relation model]


[RelationRole]​

readonly [RelationRole]: "Link"

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

[relation role]

Implementation of​

ModelLinker.[RelationRole]

Methods​

get()​

get(): Promise<T>

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

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:504

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:469

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:493

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:482

Return the string representation of the linked key

Returns​

string

the string representation