Merge pull request #11352 from waratuman/master

Adding missing static methods to Bookshelf
This commit is contained in:
Andy
2016-09-24 12:29:10 -07:00
committed by GitHub
2 changed files with 8 additions and 0 deletions

View File

@@ -71,6 +71,12 @@ class Tag extends bookshelf.Model<Tag> {
get tableName() { return 'tags'; }
}
User.where<User>('id', 1).fetch({withRelated: ['posts.tags']}).then(function(user) {
console.log(user.related('posts').toJSON());
}).catch(function(err) {
console.error(err);
});
new User().where('id', 1).fetch({withRelated: ['posts.tags']})
.then(user => {
const posts = user.related<Post>('posts');

View File

@@ -93,6 +93,8 @@ declare module 'bookshelf' {
static fetchAll<T extends Model<any>>() : Promise<Collection<T>>;
/** @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;
belongsTo<R extends Model<any>>(target : {new(...args : any[]) : R}, foreignKey? : string) : R;
belongsToMany<R extends Model<any>>(target : {new(...args : any[]) : R}, table? : string, foreignKey? : string, otherKey? : string) : Collection<R>;