# BaseModel.toGraph() method · @imqueue/pg-sequelize

Source: https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.basemodel.tograph/
Published: 2026-08-01
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/pg-sequelize 4.2.0 — generated reference, not hand-written

Builds a graph of this model's associations, following them transitively.

**Signature:**

```typescript
static toGraph(graph?: Graph<typeof BaseModel>): Graph<typeof BaseModel>;
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| graph | [Graph](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.graph/)<typeof [BaseModel](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.basemodel/)> | _(Optional)_ Graph to add to. A fresh one by default, and passing the same one is what makes the recursive calls accumulate into a single graph. |


**Returns:**

[Graph](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.graph/)<typeof [BaseModel](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.basemodel/)>

The graph, so the outermost call can use it.

## Remarks

Every association becomes an edge, and a many-to-many contributes two: this model to the through-model, and the through-model to the target. Each target is then walked in turn, and an association already present as an edge is not followed again, which is what stops a cycle from recursing forever.

The reason to have it is to find those cycles before a query does — a cycle in the graph is a query that can be asked to include itself.

