Thursday 20 April 2017

Bookshelf orm how to load plugins virtuals

I have the following in one file:

const dbConfig = require('./knexfile.js');
const knex = require('knex')(dbConfig);
const Bookshelf = require('bookshelf')(knex);
Bookshelf.plugin('virtuals');
module.exports = Bookshelf;

In another file, I am requiring such Bookshelf config. However, it says the virtual columns are not defined, I don't know why. Every other functionality works out fine only the plugins are problematic

const _ = require('lodash');
const bookshelf = require('../knex_config.js');


let Department = bookshelf.Model.extend({
  tableName: 'departments',
  idAttribute: 'department_id',
  virtuals: {
    netSales: function() {
        return this.get('total_sales') - this.get('over_head_costs');
    }
  }
}



via WABBIT0111

No comments:

Post a Comment