From 6400da610d0189eaf286be19982eb1389b308221 Mon Sep 17 00:00:00 2001 From: postpersonality Date: Mon, 6 Jun 2016 18:10:38 +0300 Subject: [PATCH] fix Sequelize.FindOptions to be able to use Sequelize.cast in arguments (#9536) --- sequelize/sequelize-tests.ts | 4 +++- sequelize/sequelize.d.ts | 11 ++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/sequelize/sequelize-tests.ts b/sequelize/sequelize-tests.ts index 4fedb55c5f..5a1dfe4def 100644 --- a/sequelize/sequelize-tests.ts +++ b/sequelize/sequelize-tests.ts @@ -888,10 +888,12 @@ User.findAll( { include : [User], order : [['id', 'ASC NULLS LAST'], [User, 'id' User.findAll( { include : [{ model : User, where : { title : 'DoDat' }, include : [{ model : User }] }] } ); User.findAll( { attributes: ['username', 'data']}); User.findAll( { attributes: {include: ['username', 'data']} }); -User.findAll( { attributes: [['username', 'UNM'], ['email', 'EML']] }); +User.findAll( { attributes: [['username', 'user_name'], ['email', 'user_email']] }); User.findAll( { attributes: [s.fn('count', Sequelize.col('*'))] }); User.findAll( { attributes: [[s.fn('count', Sequelize.col('*')), 'count']] }); User.findAll( { attributes: [[s.fn('count', Sequelize.col('*')), 'count']], group: ['sex'] }); +User.findAll( { attributes: [s.cast(s.fn('count', Sequelize.col('*')), 'INTEGER')] }); +User.findAll( { attributes: [[s.cast(s.fn('count', Sequelize.col('*')), 'INTEGER'), 'count']] }); User.findById( 'a string' ); diff --git a/sequelize/sequelize.d.ts b/sequelize/sequelize.d.ts index df87d5a20f..cc0ff0b4ff 100644 --- a/sequelize/sequelize.d.ts +++ b/sequelize/sequelize.d.ts @@ -3115,17 +3115,22 @@ declare module "sequelize" { } + /** + * Shortcut for types used in FindOptions.attributes + */ + type FindOptionsAttriburesArray = Array; + /** * Options that are passed to any model creating a SELECT query * * A hash of options to describe the scope of the search */ - interface FindOptions { + interface FindOptions { /** * A hash of attributes to describe your search. See above for examples. */ - where? : WhereOptions | Array; + where?: WhereOptions | Array; /** * A list of the attributes that you want to select. To rename an attribute, you can pass an array, with @@ -3133,7 +3138,7 @@ declare module "sequelize" { * `Sequelize.literal`, `Sequelize.fn` and so on), and the second is the name you want the attribute to * have in the returned instance */ - attributes?: Array | { include?: Array, exclude?: Array }; + attributes?: FindOptionsAttriburesArray | { include?: FindOptionsAttriburesArray, exclude?: Array }; /** * If true, only non-deleted records will be returned. If false, both deleted and non-deleted records will