不要怂,就是干,撸起袖子干!

Commit 42927d3e by Simon Schick Committed by GitHub

fix(types): add duplicating option (#10871)

1 parent 48eafaa5
...@@ -1646,6 +1646,7 @@ class Model { ...@@ -1646,6 +1646,7 @@ class Model {
* @param {Object} [options.include[].through.where] Filter on the join model for belongsToMany relations * @param {Object} [options.include[].through.where] Filter on the join model for belongsToMany relations
* @param {Array} [options.include[].through.attributes] A list of attributes to select from the join model for belongsToMany relations * @param {Array} [options.include[].through.attributes] A list of attributes to select from the join model for belongsToMany relations
* @param {Array<Object|Model|string>} [options.include[].include] Load further nested related models * @param {Array<Object|Model|string>} [options.include[].include] Load further nested related models
* @param {boolean} [options.include[].duplicating] Mark the include as duplicating, will prevent a subquery from being used.
* @param {Array|Sequelize.fn|Sequelize.col|Sequelize.literal} [options.order] Specifies an ordering. Using an array, you can provide several columns / functions to order by. Each element can be further wrapped in a two-element array. The first element is the column / function to order by, the second is the direction. For example: `order: [['name', 'DESC']]`. In this way the column will be escaped, but the direction will not. * @param {Array|Sequelize.fn|Sequelize.col|Sequelize.literal} [options.order] Specifies an ordering. Using an array, you can provide several columns / functions to order by. Each element can be further wrapped in a two-element array. The first element is the column / function to order by, the second is the direction. For example: `order: [['name', 'DESC']]`. In this way the column will be escaped, but the direction will not.
* @param {number} [options.limit] Limit for result * @param {number} [options.limit] Limit for result
* @param {number} [options.offset] Offset for result * @param {number} [options.offset] Offset for result
......
...@@ -374,6 +374,10 @@ export type Includeable = typeof Model | Association | IncludeOptions | { all: t ...@@ -374,6 +374,10 @@ export type Includeable = typeof Model | Association | IncludeOptions | { all: t
*/ */
export interface IncludeOptions extends Filterable, Projectable, Paranoid { export interface IncludeOptions extends Filterable, Projectable, Paranoid {
/** /**
* Mark the include as duplicating, will prevent a subquery from being used.
*/
duplicating?: boolean;
/**
* The model you want to eagerly load * The model you want to eagerly load
*/ */
model?: typeof Model; model?: typeof Model;
......
import { Model, Sequelize, HasMany } from 'sequelize'; import { Model, Sequelize, HasMany } from 'sequelize';
class MyModel extends Model { class MyModel extends Model {
public static associations: { public static associations: {
relation: HasMany relation: HasMany
}; };
} }
class AssociatedModel extends Model {} class AssociatedModel extends Model {}
MyModel.findAll({ MyModel.findAll({
include: [ include: [
{ {
limit: 1, duplicating: true,
model: AssociatedModel, limit: 1,
on: { model: AssociatedModel,
a: 1, on: {
}, a: 1,
order: [['id', 'DESC']], },
separate: true, order: [['id', 'DESC']],
where: { state: Sequelize.col('project.state') }, separate: true,
}, where: { state: Sequelize.col('project.state') },
], },
],
}); });
MyModel.findAll({ MyModel.findAll({
include: [{ all: true }], include: [{ all: true }],
}); });
MyModel.findAll({ MyModel.findAll({
include: [{ include: [{
limit: 1, limit: 1,
association: 'relation', association: 'relation',
order: [['id', 'DESC']], order: [['id', 'DESC']],
separate: true, separate: true,
where: { state: Sequelize.col('project.state') }, where: { state: Sequelize.col('project.state') },
}] }]
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!