Skip to content

Instantly share code, notes, and snippets.

@luggage66
Created September 16, 2015 19:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luggage66/8920135a556fc33b06ac to your computer and use it in GitHub Desktop.
Save luggage66/8920135a556fc33b06ac to your computer and use it in GitHub Desktop.
Bookshelf.js 0.8.2 static method inheritance monkey-punching
export default function fixBookShelfES6Inheritance(target) {
// console.log('Fixing:', target.name);
let parentConstructor = Object.getPrototypeOf(target.prototype).constructor;
let parentStaticProperties = Object.keys(parentConstructor);
// console.log('Adding static properties:', parentStaticProperties);
// TODO: Deal with static methods that want to call super() (right now they are REPLACED!)
parentStaticProperties.forEach(propName => target[propName] = parentStaticProperties[propName]);
}
import BookshelfModelDecorator from './fixBookShelfES6Inheritance';
@BookshelfModelDecorator
export default class User extends bookshelf.Model
{
get tableName() { return 'User'; }
constructor(attr, options) {
super(attr, options);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment