Skip to content

Instantly share code, notes, and snippets.

@kamilziajka
Last active March 11, 2016 14:29
Show Gist options
  • Save kamilziajka/25da3a45d36e3f6f840f to your computer and use it in GitHub Desktop.
Save kamilziajka/25da3a45d36e3f6f840f to your computer and use it in GitHub Desktop.
bookshelf virtual property alias
const bookshelf = Bookshelf(knex).plugin('virtuals');
const alias = (property) => ({
get: function () {
return this.get(property)
},
set: function (value) {
this.set(property, value)
}
});
const Foo = bookshelf.model('Foo', {
tableName: 'foo',
virtuals: {
$id: alias('foo_id'),
name: alias('foo_name')
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment