From ad99b8e21772a3f92a64fe0dcd8d47d8e1b5036e Mon Sep 17 00:00:00 2001 From: John Pinkster Date: Fri, 2 Jun 2017 10:21:01 -0400 Subject: [PATCH] Sequelize - FIX/SubQuery and Raw (#16657) * Sequelize - FIX/SubQuery and Raw In the `FindOptions` there is an optional property missing from the definition file that allows you to turn on and off sub queries with nested associations Documentation of functionality: https://github.com/sequelize/sequelize/issues/1756 Please fill in this template. - [ ] Use a meaningful title for the pull request. Include the name of the package modified. - [ ] Test the change in your own code. (Compile and run.) - [ ] Follow the advice from the [readme](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#make-a-pull-request). - [ ] Avoid [common mistakes](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#common-mistakes). - [ ] Run `npm run lint package-name` (or `tsc` if no `tslint.json` is present). Select one of these and delete the others: If adding a new definition: - [ ] The package does not provide its own types, and you can not add them. - [ ] If this is for an NPM package, match the name. If not, do not conflict with the name of an NPM package. - [ ] Create it with `dts-gen --dt`, not by basing it on an existing project. - [ ] `tslint.json` should be present, and `tsconfig.json` should have `noImplicitAny`, `noImplicitThis`, and `strictNullChecks` set to `true`. If changing an existing definition: - [ ] Provide a URL to documentation or source code which provides context for the suggested changes: <> - [ ] Increase the version number in the header if appropriate. - [ ] If you are making substantial changes, consider adding a `tslint.json` containing `{ "extends": "../tslint.json" }`. If removing a declaration: - [ ] If a package was never on DefinitelyTyped, you don't need to do anything. (If you wrote a package and provided types, you don't need to register it with us.) - [ ] Delete the package's directory. - [ ] Add it to `notNeededPackages.json`. * Adding test --- types/sequelize/index.d.ts | 12 ++++++++---- types/sequelize/sequelize-tests.ts | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/types/sequelize/index.d.ts b/types/sequelize/index.d.ts index be89371b83..47eb708e25 100644 --- a/types/sequelize/index.d.ts +++ b/types/sequelize/index.d.ts @@ -3171,7 +3171,6 @@ declare namespace sequelize { * be returned. Only applies if `options.paranoid` is true for the model. */ paranoid?: boolean; - } /** @@ -3244,13 +3243,13 @@ declare namespace sequelize { raw?: boolean; /** - * having ?!? + * having ?!? */ having?: WhereOptions; /** - * Group by. It is not mentioned in sequelize's JSDoc, but mentioned in docs. - * https://github.com/sequelize/sequelize/blob/master/docs/docs/models-usage.md#user-content-manipulating-the-dataset-with-limit-offset-order-and-group + * Group by. It is not mentioned in sequelize's JSDoc, but mentioned in docs. + * https://github.com/sequelize/sequelize/blob/master/docs/docs/models-usage.md#user-content-manipulating-the-dataset-with-limit-offset-order-and-group */ group?: string | string[] | Object; @@ -3259,6 +3258,11 @@ declare namespace sequelize { * Apply DISTINCT(col) for FindAndCount(all) */ distinct?: boolean; + + /** + * Prevents a subquery on the main table when using include + */ + subQuery?: boolean; } /** diff --git a/types/sequelize/sequelize-tests.ts b/types/sequelize/sequelize-tests.ts index 830b323dcc..4363de9580 100644 --- a/types/sequelize/sequelize-tests.ts +++ b/types/sequelize/sequelize-tests.ts @@ -913,6 +913,8 @@ User.findAll( { attributes: [[s.fn('count', Sequelize.col('*')), 'count']], grou User.findAll( { attributes: [s.cast(s.fn('count', Sequelize.col('*')), 'INTEGER')] }); User.findAll( { attributes: [[s.cast(s.fn('count', Sequelize.col('*')), 'INTEGER'), 'count']] }); User.findAll( { where : s.fn('count', [0, 10]) } ); +User.findAll( { subQuery: false, include : [User], order : [[User, User, 'numYears', 'c']] } ); + User.findById( 'a string' );