Skip to main content
zerotal

Documentation


Documentation / zerotal / orm / ManyToMany

Interface: ManyToMany<T>

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:86

Return type for manyToMany relation properties. Extends Array so every array operation (map, filter, for-of, spread, destructuring) works without casting, while adding fully-typed pivot manipulation methods.

On an unloaded model the pivot methods (attach / detach / sync / toggle) still function — they hit the DB directly using the parent's primary key. Array access on an unloaded relation throws RelationNotLoadedError.

Extends

  • Array<T>

Type Parameters

T

T

Indexable

[n: number]: T

Methods

attach()

attach(id, pivotData?): Promise<void>

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:88

Insert pivot rows linking the parent to the given related id(s). Ignores duplicates.

Parameters

id

number | number[]

pivotData?

Record<string, unknown>

Returns

Promise<void>


detach()

detach(id?): Promise<void>

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:90

Remove pivot rows for the given related id(s), or all rows if omitted.

Parameters

id?

number | number[]

Returns

Promise<void>


sync()

sync(ids): Promise<void>

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:92

Replace all pivot rows with exactly the given related ids.

Parameters

ids

number[]

Returns

Promise<void>


toggle()

toggle(id): Promise<void>

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:94

Attach ids that are missing; detach ids that already exist.

Parameters

id

number | number[]

Returns

Promise<void>


syncWithoutDetaching()

syncWithoutDetaching(ids): Promise<void>

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:96

Attach ids without detaching existing ones (no duplicates created).

Parameters

ids

number[]

Returns

Promise<void>


updateExistingPivot()

updateExistingPivot(id, pivotData): Promise<void>

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:98

Update extra pivot columns on an existing pivot row.

Parameters

id

number

pivotData

Record<string, unknown>

Returns

Promise<void>