[**Documentation**](../../../README)

***

[Documentation](../../../README) / [zerotal](../../README) / [orm](../README) / ManyToMany

# Interface: ManyToMany\<T\>

Defined in: [packages/orm/src/model/relations/RelationRegistry.ts:86](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/orm/src/model/relations/RelationRegistry.ts#L86)

Return type for manyToMany relation properties. Extends Array<T> 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](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/orm/src/model/relations/RelationRegistry.ts#L88)

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](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/orm/src/model/relations/RelationRegistry.ts#L90)

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](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/orm/src/model/relations/RelationRegistry.ts#L92)

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](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/orm/src/model/relations/RelationRegistry.ts#L94)

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](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/orm/src/model/relations/RelationRegistry.ts#L96)

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](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/orm/src/model/relations/RelationRegistry.ts#L98)

Update extra pivot columns on an existing pivot row.

#### Parameters

##### id

`number`

##### pivotData

`Record`\<`string`, `unknown`\>

#### Returns

`Promise`\<`void`\>
