Skip to content

WriteManyRelationInstance

Adds and removes targets on a Relation side that holds any number of them.

When the Relation declares an Event, each newly added target publishes it with the action added, each removed target with removed, and each target dropped by clear with cleared.

TItem extends WriteItem

The type of the target Items.

readonly type: "many"

Discriminates this side as holding any number of targets.

ReadManyRelationInstance.type

add(target): Promise<boolean>

Relates an Item as a target of this Relation.

TItem

The Item to relate; its Template must be the target Template or a member of the target Union.

Promise<boolean>

true when the Item was newly related; false when it was already a target.

(error-012-incorrect-item-for-relation) when the Item’s Template is not accepted by the Relation.

Add a tag

await recognition.relations.tags.add(tagItem);

add(targets): Promise<boolean[]>

Relates several Items as targets of this Relation in one operation.

TItem[]

The Items to relate; each Template must be the target Template or a member of the target Union.

Promise<boolean[]>

For each Item, in the order given, true when it was newly related and false when it was already a target.

(error-012-incorrect-item-for-relation) when an Item’s Template is not accepted by the Relation.


addIfNotExists(target, condition?): Promise<boolean>

Relates an Item only when it is not already a target, or when the existing Relation to it has expired under the condition.

TItem

The Item to relate.

IfNotExistCondition

Treats an existing Relation to this Item older than existingMaxAge milliseconds as absent.

Promise<boolean>

true when the Relation was added; false when an existing Relation blocked it.

Uniqueness is judged per pair of Items, so other targets of this side are unaffected. The check and the write are one atomic operation.

IfNotExistCondition


clear(): Promise<void>

Removes every target from this side of the Relation.

Promise<void>


isType(item): item is TItem

Reports whether an Item may be a target on this side of the Relation: its Template is the target Template or a member of the target Union.

BaseReadItem

The Item to test.

item is TItem

ReadManyRelationInstance.isType


remove(target): Promise<boolean>

Removes an Item from the targets of this Relation.

TItem

The Item to remove.

Promise<boolean>

true when the Item was a target and was removed; false when it was not a target.

remove(targets): Promise<boolean[]>

Removes several Items from the targets of this Relation in one operation.

TItem[]

The Items to remove.

Promise<boolean[]>

For each Item, in the order given, true when it was a target and was removed and false otherwise.


select(options?): TemplateItemCursorSelector<RelatedItem<TItem>>

Starts a selection over the targets of this Relation, each carrying its Relation metadata.

RelationSelectOptions

Whether to include targets whose Relation has been removed.

TemplateItemCursorSelector<RelatedItem<TItem>>

The selection accepts the same narrowing, filtering, sorting and paging as any Template selection, including archived.

ReadManyRelationInstance.select