Skip to content

postgrelize / IncludeOptions

Type Alias: IncludeOptions ​

IncludeOptions = object

Defined in: src/associations/include.ts:44

One include entry (Sequelize v6 IncludeOptions): which association to load and how.

Name the association with model, as or association. Eager loading uses JOINs (see the guide), except separate, which runs another query.

See ​

FindOptions

Example ​

ts
const opts: IncludeOptions = {
  model: Post,
  as: 'posts',
  where: { published: true },
  required: false,
  attributes: ['id', 'title'],
  include: [{ model: Tag }],
};
const users = await User.findAll({ include: [opts] });

Properties ​

all? ​

optional all?: boolean

Defined in: src/associations/include.ts:90

Include every association of the model ({ all: true }).

Default Value ​

ts
false

as? ​

optional as?: string

Defined in: src/associations/include.ts:48

Alias of the association, as given when it was defined.


association? ​

optional association?: Association | string

Defined in: src/associations/include.ts:50

Association object or alias.


attributes? ​

optional attributes?: FindAttributeOptions

Defined in: src/associations/include.ts:64

Selected attributes.


include? ​

optional include?: IncludeOption

Defined in: src/associations/include.ts:66

Nested includes.


lateral? ​

optional lateral?: boolean

Defined in: src/associations/include.ts:80

postgrelize extension

Fetch only the first limit rows per parent in the database (JOIN LATERAL over the parent keys) instead of loading every child and trimming in memory. Needs separate and limit. PostgreSQL extension.

Default Value ​

ts
false

limit? ​

optional limit?: number

Defined in: src/associations/include.ts:84

Maximum rows per include of a separate include.


model? ​

optional model?: Model

Defined in: src/associations/include.ts:46

Associated model; the association is looked up by model (and as).


on? ​

optional on?: unknown

Defined in: src/associations/include.ts:57

Custom ON condition of the join; replaces the condition derived from the association keys. Not used by belongsToMany includes (the junction joins keep their key conditions). See WhereOptions.


order? ​

optional order?: unknown

Defined in: src/associations/include.ts:82

Order of a separate include.


paranoid? ​

optional paranoid?: boolean

Defined in: src/associations/include.ts:87

For paranoid targets: false includes soft-deleted rows.

Default Value ​

ts
true

required? ​

optional required?: boolean

Defined in: src/associations/include.ts:59

INNER JOIN (true) or LEFT OUTER JOIN (false).


optional right?: boolean

Defined in: src/associations/include.ts:62

Use RIGHT OUTER JOIN.

Default Value ​

ts
false

separate? ​

optional separate?: boolean

Defined in: src/associations/include.ts:69

Load a hasMany association with a separate query instead of a JOIN.

Default Value ​

ts
false

through? ​

optional through?: IncludeThroughOptions

Defined in: src/associations/include.ts:71

Junction options for belongsToMany.


where? ​

optional where?: unknown

Defined in: src/associations/include.ts:52

Filter on the included rows; makes the include required unless required: false. See WhereOptions.

Released under the MIT License.