WriteManyRelationInstance
Adds and removes targets on a Relation side that holds any number of them.
Remarks
Section titled “Remarks”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.
Extends
Section titled “Extends”ReadManyRelationInstance<TItem>
Type Parameters
Section titled “Type Parameters”TItem extends WriteItem
The type of the target Items.
Properties
Section titled “Properties”
readonlytype:"many"
Discriminates this side as holding any number of targets.
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”Call Signature
Section titled “Call Signature”add(
target):Promise<boolean>
Relates an Item as a target of this Relation.
Parameters
Section titled “Parameters”target
Section titled “target”TItem
The Item to relate; its Template must be the target Template or a member of the target Union.
Returns
Section titled “Returns”Promise<boolean>
true when the Item was newly related; false when it was already a target.
Throws
Section titled “Throws”(error-012-incorrect-item-for-relation) when the Item’s Template is not accepted by the Relation.
Example
Section titled “Example”Add a tag
await recognition.relations.tags.add(tagItem);Call Signature
Section titled “Call Signature”add(
targets):Promise<boolean[]>
Relates several Items as targets of this Relation in one operation.
Parameters
Section titled “Parameters”targets
Section titled “targets”TItem[]
The Items to relate; each Template must be the target Template or a member of the target Union.
Returns
Section titled “Returns”Promise<boolean[]>
For each Item, in the order given, true when it was newly related and false when it was already a target.
Throws
Section titled “Throws”(error-012-incorrect-item-for-relation) when an Item’s Template is not accepted by the Relation.
addIfNotExists()
Section titled “addIfNotExists()”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.
Parameters
Section titled “Parameters”target
Section titled “target”TItem
The Item to relate.
condition?
Section titled “condition?”Treats an existing Relation to this Item older than existingMaxAge milliseconds as absent.
Returns
Section titled “Returns”Promise<boolean>
true when the Relation was added; false when an existing Relation blocked it.
Remarks
Section titled “Remarks”Uniqueness is judged per pair of Items, so other targets of this side are unaffected. The check and the write are one atomic operation.
clear()
Section titled “clear()”clear():
Promise<void>
Removes every target from this side of the Relation.
Returns
Section titled “Returns”Promise<void>
isType()
Section titled “isType()”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.
Parameters
Section titled “Parameters”The Item to test.
Returns
Section titled “Returns”item is TItem
Inherited from
Section titled “Inherited from”ReadManyRelationInstance.isType
remove()
Section titled “remove()”Call Signature
Section titled “Call Signature”remove(
target):Promise<boolean>
Removes an Item from the targets of this Relation.
Parameters
Section titled “Parameters”target
Section titled “target”TItem
The Item to remove.
Returns
Section titled “Returns”Promise<boolean>
true when the Item was a target and was removed; false when it was not a target.
Call Signature
Section titled “Call Signature”remove(
targets):Promise<boolean[]>
Removes several Items from the targets of this Relation in one operation.
Parameters
Section titled “Parameters”targets
Section titled “targets”TItem[]
The Items to remove.
Returns
Section titled “Returns”Promise<boolean[]>
For each Item, in the order given, true when it was a target and was removed and false otherwise.
select()
Section titled “select()”select(
options?):TemplateItemCursorSelector<RelatedItem<TItem>>
Starts a selection over the targets of this Relation, each carrying its Relation metadata.
Parameters
Section titled “Parameters”options?
Section titled “options?”Whether to include targets whose Relation has been removed.
Returns
Section titled “Returns”TemplateItemCursorSelector<RelatedItem<TItem>>
Remarks
Section titled “Remarks”The selection accepts the same narrowing, filtering, sorting and paging as any Template selection,
including archived.

