Optional
attributesIf an array: a list of the attributes that you want to select.
Attributes can also be raw SQL (literal
), fn
, and col
To rename an attribute, you can pass an array, with two elements:
literal
, fn
, col
),If include
is used: selects all the attributes of the model,
plus some additional ones. Useful for aggregations.
{ attributes: { include: [[literal('COUNT(id)'), 'total']] }
If exclude
is used: selects all the attributes of the model,
except the one specified in exclude. Useful for security purposes
{ attributes: { exclude: ['password'] } }
Optional
benchmarkPass query execution time in milliseconds as second argument to logging function (options.logging).
Optional
bindEither an object of named parameter bindings in the format $param
or an array of unnamed
values to bind to $1
, $2
, etc in your SQL.
Optional
fieldMap returned fields to arbitrary names for SELECT query type if options.fieldMaps
is present.
Optional
groupGROUP BY in sql
Optional
groupedOptional
havingSelect group rows after groups and aggregates are computed.
Optional
includeA list of associations to eagerly load using a left join (a single association is also supported).
See Includeable to see how to specify the association, and its eager-loading options.
Optional
indexMySQL only.
Optional
instanceA sequelize instance used to build the return instance
Optional
limitLimits how many items will be retrieved by the operation.
If limit
and include
are used together, Sequelize will turn the subQuery
option on by default.
This is done to ensure that limit
only impacts the Model on the same level as the limit
option.
You can disable this behavior by explicitly setting subQuery: false
, however limit
will then
affect the total count of returned values, including eager-loaded associations, instead of just one table.
// in the following query, `limit` only affects the "User" model.
// This will return 2 users, each including all of their projects.
User.findAll({
limit: 2,
include: [User.associations.projects],
});
// in the following query, `limit` affects the total number of returned values, eager-loaded associations included.
// This may return 2 users, each with one project,
// or 1 user with 2 projects.
User.findAll({
limit: 2,
include: [User.associations.projects],
subQuery: false,
});
Optional
lockLock the selected rows. Possible options are transaction.LOCK.UPDATE and transaction.LOCK.SHARE. Postgres also supports transaction.LOCK.KEY_SHARE, transaction.LOCK.NO_KEY_UPDATE and specific model locks with joins. See LOCK.
Optional
loggingA function that gets executed while running the query to log the sql.
Optional
mapMap returned fields to model's fields if options.model
or options.instance
is present.
Mapping will occur before building the model instance.
Optional
nestIf true, transforms objects with .
separated property names into nested objects using
dottie.js. For example { 'user.username': 'john' } becomes
{ user: { username: 'john' }}. When nest
is true, the query type is assumed to be 'SELECT'
,
unless otherwise specified
false
Optional
offsetSkip the first n items of the results.
Optional
orderSpecifies an ordering. If a string is provided, it will be escaped.
Using an array, you can provide several attributes / functions to order by. Each element can be further wrapped in a two-element array:
order: [['name', 'DESC']]
.
The attribute will be escaped, but the direction will not.
Optional
paranoidIf true, only non-deleted records will be returned. If false, both deleted and non-deleted records will be returned.
Only applies if paranoid is true for the model.
true
Optional
plainSets the query type to SELECT
and return a single row
Optional
rawReturn raw result. See query for more information.
Optional
rejectThrows an error if the query would return 0 results.
Optional
replacementsEither an object of named parameter replacements in the format :param
or an array of unnamed
replacements to replace ?
in your SQL.
Optional
retryOptional
schemaApply a schema on the related model
Optional
schemaOptional
scopeApply a scope on the related model, or remove its default scope by passing false.
Optional
searchAn optional parameter to specify the schema search_path (Postgres only)
Optional
skipSkip locked rows. Only supported in Postgres.
Optional
subUse sub queries (internal).
If unspecified, this will true
by default if limit
is specified, and false
otherwise.
See limit for more information.
Optional
transactionThe transaction in which this query must be run.
If CLS is enabled and a transaction is running in the current CLS context, that transaction will be used, unless null or a Transaction is manually specified here.
Optional
typeThe type of query you are executing. The query type affects how results are formatted before they are
passed back. The type is a string, but Sequelize.QueryTypes
is provided as convenience shortcuts.
Optional
useForce the query to use the write pool, regardless of the query type.
false
Optional
whereThe WHERE
clause. Can be many things from a hash of attributes to raw SQL.
Visit https://sequelize.org/docs/v7/core-concepts/model-querying-basics/ for more information.
Generated using TypeDoc
The options for the hasAssociation mixin of the hasMany association.
See
HasManyHasAssociationMixin