Merge pull request #19018 from vesse/bookshelf/enable-where-in-query

[bookshelf] Allow array value for 'in' query
This commit is contained in:
Bowden Kelly
2017-08-22 10:58:01 -07:00
committed by GitHub
2 changed files with 13 additions and 2 deletions

View File

@@ -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 */
{

View File

@@ -97,7 +97,7 @@ declare namespace Bookshelf {
/** @deprecated should use `new` objects instead. */
static forge<T>(attributes?: any, options?: ModelOptions): T;
static where<T>(properties: { [key: string]: any }): T;
static where<T>(key: string, operatorOrValue: string | number | boolean, valueIfOperator?: string | number | boolean): T;
static where<T>(key: string, operatorOrValue: string | number | boolean, valueIfOperator?: string | string[] | number | number[] | boolean): T;
belongsTo<R extends Model<any>>(target: { new (...args: any[]): R }, foreignKey?: string, foreignKeyTarget?: string): R;
belongsToMany<R extends Model<any>>(target: { new (...args: any[]): R }, table?: string, foreignKey?: string, otherKey?: string, foreignKeyTarget?: string, otherKeyTarget?: string): Collection<R>;
@@ -126,7 +126,7 @@ declare namespace Bookshelf {
save(attrs?: { [key: string]: any }, options?: SaveOptions): BlueBird<T>;
through<R extends Model<any>>(interim: ModelSubclass, 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