Skip to main content

ModelRefCustomMap

@webda/models


Class: ModelRefCustomMap<T, K>

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

Define a ModelRef with custom properties for map Exclude the PrimaryKey from the JSON

Deprecated​

Extends​

  • ModelRefCustom<T, K>

Type Parameters​

T​

T extends Storable

K​

K

Constructors​

Constructor​

new ModelRefCustomMap<T, K>(key, repo, data, parent?): ModelRefCustomMap<T, K>

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

Create a new ModelRefCustom

Parameters​

key​

PrimaryKeyType<T>

the primary key of the referenced object

repo​

Repository<ModelClass<T>>

the repository managing the referenced model

data​

K

custom data associated with this reference

parent?​

Storable<any, any>

optional parent storable

Returns​

ModelRefCustomMap<T, K>

Inherited from​

ModelRefCustom<T, K>.constructor

Properties​

[RelationData]​

protected [RelationData]: K

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

Inherited from​

ModelRefCustom.[RelationData]


[RelationKey]?​

optional [RelationKey]?: PrimaryKeyType<T>

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

Inherited from​

ModelRefCustom.[RelationKey]


[RelationRepository]?​

optional [RelationRepository]?: Repository<ModelClass<T>>

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

Inherited from​

ModelRefCustom.[RelationRepository]

Methods​

delete()​

delete<A>(conditionField?, condition?): Promise<void>

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

Delete the model

If a condition is specified, it will be used to check if the model can be deleted

Type Parameters​

A​

A extends string

Parameters​

conditionField?​

A

optional field for optimistic locking

condition?​

_PropertyPathType<T, A> | JSONed<_PropertyPathType<T, A>>

expected value for the condition field

Returns​

Promise<void>

a promise resolving when complete

Inherited from​

ModelRefCustom.delete


deleteItemFromCollection()​

deleteItemFromCollection<K, L>(collection, index, itemWriteConditionField?, itemWriteCondition?): Promise<void>

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

Remove an item from a collection

Type Parameters​

K​

K extends string

L​

L extends string | number | symbol

Parameters​

collection​

K

the collection field name

index​

number

the position to remove from

itemWriteConditionField?​

L

optional field for item write condition

itemWriteCondition?​

ArrayElement<T[K]>[L]

expected value for the item write condition

Returns​

Promise<void>

a promise resolving when complete

Inherited from​

ModelRefCustom.deleteItemFromCollection


exists()​

exists(): Promise<boolean>

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

Check if the model exists in the repository

Returns​

Promise<boolean>

true if the model exists

Inherited from​

ModelRefCustom.exists


get()​

get(): Promise<T>

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

Get the model referenced by the key

Returns​

Promise<T>

the resolved model instance

Inherited from​

ModelRefCustom.get


getKey()​

protected getKey(): PrimaryKeyType<T>

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

Get the primary key and ensure it's initialized

Returns​

PrimaryKeyType<T>

the primary key value

Inherited from​

ModelRefCustom.getKey


getPrimaryKey()​

getPrimaryKey(): PrimaryKeyType<T>

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

Get the model

Returns​

PrimaryKeyType<T>

the primary key value

Inherited from​

ModelRefCustom.getPrimaryKey


getRepository()​

protected getRepository(): Repository<ModelClass<T>>

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

Get the repository and ensure it's initialized

Returns​

Repository<ModelClass<T>>

the repository instance

Inherited from​

ModelRefCustom.getRepository


incrementAttribute()​

incrementAttribute(property, value?, conditionField?, condition?): Promise<void | Record<string, number>>

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

Increment only one attribute of the model

Parameters​

property​

NumericPropertyPaths<T>

the numeric property to increment

value?​

number

the increment amount

conditionField?​

_NonFunctionPropertyPaths<T>

optional field for optimistic locking

condition?​

_PropertyPathType<T, _NonFunctionPropertyPaths<T>>

expected value for the condition field

Returns​

Promise<void | Record<string, number>>

a promise resolving when complete

Inherited from​

ModelRefCustom.incrementAttribute


incrementAttributes()​

incrementAttributes(info, conditionField?, condition?): Promise<void | Record<string, number>>

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

Increment the attributes of the model

Parameters​

info​

(NumericPropertyPaths<T> | { property: NumericPropertyPaths<T>; value?: number; })[] | Record<NumericPropertyPaths<T>, number>

The attributes to increment

conditionField?​

_NonFunctionPropertyPaths<T>

optional field for optimistic locking

condition?​

_PropertyPathType<T, _NonFunctionPropertyPaths<T>>

expected value for the condition field

Returns​

Promise<void | Record<string, number>>

a promise resolving when complete

Inherited from​

ModelRefCustom.incrementAttributes


patch()​

patch<K, A>(data, conditionField?, condition?): Promise<void>

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

Patch the model

Type Parameters​

K​

K extends string | number | symbol

A​

A extends string

Parameters​

data​

Partial<Omit<T, PrimaryKeyAttributes<T>>>

the partial data to patch

conditionField?​

A

optional field for optimistic locking

condition?​

_PropertyPathType<T, A>

expected value for the condition field

Returns​

Promise<void>

a promise resolving when complete

Inherited from​

ModelRefCustom.patch


removeAttribute()​

removeAttribute<A>(attribute, conditionField?, condition?): Promise<void>

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

Remove an attribute from the model

Type Parameters​

A​

A extends string

Parameters​

attribute​

Exclude<_NonFunctionPropertyPaths<T>, PrimaryKeyAttributes<T>>

the attribute to remove

conditionField?​

A

optional field for optimistic locking

condition?​

_PropertyPathType<T, A>

expected value for the condition field

Returns​

Promise<void>

a promise resolving when complete

Inherited from​

ModelRefCustom.removeAttribute


setAttribute()​

setAttribute<A>(attribute, value): Promise<void>

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

Set the attribute of the model

Type Parameters​

A​

A extends string

Parameters​

attribute​

A

the attribute path to set

value​

JSONed<_PropertyPathType<T, A>>

the new attribute value

Returns​

Promise<void>

a promise resolving when complete

Inherited from​

ModelRefCustom.setAttribute


toJSON()​

toJSON(): any

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

Serialize the relation data as a plain object (excluding the primary key).

Returns​

any

the relation data

Overrides​

ModelRefCustom.toJSON


update()​

update<A>(data, conditionField?, condition?): Promise<void>

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

Fully replace the model data (except primary key fields)

Type Parameters​

A​

A extends string

Parameters​

data​

Omit<Helpers<T>, PrimaryKeyAttributes<T>>

Complete model data excluding primary key

conditionField?​

A

Optional field for optimistic locking

condition?​

_PropertyPathType<T, A>

Expected value for the condition field

Returns​

Promise<void>

a promise resolving when complete

Inherited from​

ModelRefCustom.update


upsertItemToCollection()​

upsertItemToCollection<K, L>(collection, item, index?, itemWriteConditionField?, itemWriteCondition?): Promise<void>

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

Add an item to a collection

Type Parameters​

K​

K extends string

L​

L extends string | number | symbol

Parameters​

collection​

K

the collection field name

item​

ArrayElement<T[K]> | JSONed<ArrayElement<T[K]>>

the item to add or update

index?​

number

optional position to insert at

itemWriteConditionField?​

ArrayElement<T[K]> extends object ? L : never

optional field for item write condition

itemWriteCondition?​

ArrayElement<T[K]> extends object ? object & ArrayElement<T[K]>[L] : ArrayElement<T[K]> | null

expected value for the item write condition

Returns​

Promise<void>

a promise resolving when complete

Inherited from​

ModelRefCustom.upsertItemToCollection