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

Commit 43ba131e by Martin Mena Committed by Sushant

fix(types): add Includeable to IncludeOptions.include type (#11622)

1 parent 757a986c
Showing with 16 additions and 8 deletions
......@@ -513,13 +513,13 @@ type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
*/
export interface FindOptions extends QueryOptions, Filterable, Projectable, Paranoid, IndexHintable {
/**
* A list of associations to eagerly load using a left join. Supported is either
* `{ include: [ Model1, Model2, ...]}`, `{ include: [{ model: Model1, as: 'Alias' }]}` or
* A list of associations to eagerly load using a left join (a single association is also supported). Supported is either
* `{ include: Model1 }`, `{ include: [ Model1, Model2, ...]}`, `{ include: [{ model: Model1, as: 'Alias' }]}` or
* `{ include: [{ all: true }]}`.
* If your association are set up with an `as` (eg. `X.hasMany(Y, { as: 'Z }`, you need to specify Z in
* the as attribute when eager loading Y).
*/
include?: Includeable[];
include?: Includeable | Includeable[];
/**
* Specifies an ordering. If a string is provided, it will be escaped. Using an array, you can provide
......@@ -588,7 +588,7 @@ export interface CountOptions extends Logging, Transactionable, Filterable, Proj
/**
* Include options. See `find` for details
*/
include?: Includeable[];
include?: Includeable | Includeable[];
/**
* Apply COUNT(DISTINCT(col))
......@@ -637,11 +637,11 @@ export interface BuildOptions {
isNewRecord?: boolean;
/**
* an array of include options - Used to build prefetched/included model instances. See `set`
* An array of include options. A single option is also supported - Used to build prefetched/included model instances. See `set`
*
* TODO: See set
*/
include?: Includeable[];
include?: Includeable | Includeable[];
}
export interface Silent {
......@@ -757,7 +757,7 @@ export interface BulkCreateOptions extends Logging, Transactionable {
/**
* Include options. See `find` for details
*/
include?: Includeable[];
include?: Includeable | Includeable[];
/**
* Return all columns or only the specified columns for the affected rows (only for postgres)
......
import { Association, HasOne, Model, Sequelize, DataTypes } from 'sequelize';
import { Association, DataTypes, HasOne, Model, Sequelize } from 'sequelize';
class MyModel extends Model {
public num!: number;
......@@ -27,6 +27,14 @@ MyModel.hasOne(OtherModel, { as: 'OtherModelAlias' });
MyModel.findOne({ include: ['OtherModelAlias'] });
MyModel.findOne({ include: OtherModel });
MyModel.count({ include: OtherModel });
MyModel.build({ int: 10 }, { include: OtherModel });
MyModel.bulkCreate([{ int: 10 }], { include: OtherModel });
const sequelize = new Sequelize('mysql://user:user@localhost:3306/mydb');
MyModel.init({}, {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!