From 60f9770c887005895f6cca6ee12e662a67bc66f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vesa=20Poikaj=C3=A4rvi?= Date: Tue, 15 Aug 2017 18:32:25 +0300 Subject: [PATCH] [bookshelf] Allow array value for 'in' query --- types/bookshelf/bookshelf-tests.ts | 11 +++++++++++ types/bookshelf/index.d.ts | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/types/bookshelf/bookshelf-tests.ts b/types/bookshelf/bookshelf-tests.ts index f42a1bf784..f8f576e570 100644 --- a/types/bookshelf/bookshelf-tests.ts +++ b/types/bookshelf/bookshelf-tests.ts @@ -867,6 +867,10 @@ model.where('favorite_color', 'red').fetch().then(() => { model.where({favorite_color: 'red', shoe_size: 12}).fetch().then(() => { //... }); +// or +model.where('favorite_color', 'in', ['red', 'green']).fetch().then(() => { + // ... +}); /* Lodash methods, see http://bookshelfjs.org/#Model-subsection-lodash-methods */ @@ -1197,6 +1201,13 @@ ships.trigger('fetched'); /* collection.where(), see http://bookshelfjs.org/#Collection-instance-where */ +(new Author()) + .where('first_name', 'in', ['User', 'Resu']) + .fetchAll() + .then(() => { + // ... + }) + /* collection.withPivot(), see http://bookshelfjs.org/#Collection-instance-withPivot */ { diff --git a/types/bookshelf/index.d.ts b/types/bookshelf/index.d.ts index 914107816f..32e0222e88 100644 --- a/types/bookshelf/index.d.ts +++ b/types/bookshelf/index.d.ts @@ -93,7 +93,7 @@ declare namespace Bookshelf { /** @deprecated should use `new` objects instead. */ static forge(attributes?: any, options?: ModelOptions): T; static where(properties: { [key: string]: any }): T; - static where(key: string, operatorOrValue: string | number | boolean, valueIfOperator?: string | number | boolean): T; + static where(key: string, operatorOrValue: string | number | boolean, valueIfOperator?: string | string[] | number | number[] | boolean): T; belongsTo>(target: { new (...args: any[]): R }, foreignKey?: string, foreignKeyTarget?: string): R; belongsToMany>(target: { new (...args: any[]): R }, table?: string, foreignKey?: string, otherKey?: string, foreignKeyTarget?: string, otherKeyTarget?: string): Collection; @@ -122,7 +122,7 @@ declare namespace Bookshelf { save(attrs?: { [key: string]: any }, options?: SaveOptions): BlueBird; through>(interim: typeof Model, throughForeignKey?: string, otherKey?: string): R; where(properties: { [key: string]: any }): T; - where(key: string, operatorOrValue: string | number | boolean, valueIfOperator?: string | number | boolean): T; + where(key: string, operatorOrValue: string | number | boolean, valueIfOperator?: string | string[] | number | number[] | boolean): T; // See https://github.com/tgriesser/bookshelf/blob/0.9.4/src/errors.js // See https://github.com/tgriesser/bookshelf/blob/0.9.4/src/model.js#L1280