Skip to main content

ModelRelated

@webda/models


Class: ModelRelated<T, L, K>

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

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

T is the model to link to _K is the attribute in T to query

_K is not used but is required to complete the graph _K define the attribute to use to load the related objects

In SQL if current model is TableA and T is TableB, _K is the foreign key in TableB

TODO Deduce attribute from the ModelParent on the other side when "" is used

Type Parameters​

T​

T extends Storable

L​

L extends Storable

K​

K extends Extract<FilterAttributes<T, ModelLinker<L>>, string> | "" = ""

Constructors​

Constructor​

new ModelRelated<T, L, K>(targetClass, object, attribute?): ModelRelated<T, L, K>

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

Create a new ModelRelated

Parameters​

targetClass​

ModelClass<T>

the target model class

object​

L

the source object owning the relation

attribute?​

K = ...

the attribute name linking the relation

Returns​

ModelRelated<T, L, K>

Methods​

getQuery()​

getQuery(query?): WebdaQLString<T>

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

Build a WebdaQL query string that filters related objects by this model's primary key.

Parameters​

query?​

string | WebdaQLString<T>

optional additional query filter

Returns​

WebdaQLString<T>

the constructed query string


iterate()​

iterate(query, params?): AsyncIterable<T>

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

Iterate through linked objects

Parameters​

query​

WebdaQLString<T>

the query filter, optionally with ? or :name placeholders

params?​

QueryParameters

values for the placeholders: an array for ?, an object for :name

Returns​

AsyncIterable<T>

an async iterable of linked objects


query()​

query(query?, params?): Promise<{ continuationToken?: string; results: T[]; }>

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

Query the related objects

Parameters​

query?​

WebdaQLString<T> = ...

optional additional query filter, optionally with ? or :name placeholders

params?​

QueryParameters

values for the placeholders: an array for ?, an object for :name

Returns​

Promise<{ continuationToken?: string; results: T[]; }>

the query results with optional continuation token


toJSON()​

toJSON(): void

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

It is a helper and should not be serialized

Returns​

void