1.0.0 • Published 9 years ago

bookshelf-deep-changed v1.0.0

Weekly downloads
7
License
MIT
Repository
github
Last release
9 years ago

Dependencies devDependency Status Build Status

bookshelf-deep-changed

Allows bookshelf models to check whether a value you are saving is different than the existing value in the database.

Usage:

module.exports = Repository.Model.extend({
  tableName: 'users',
  initialize: function () {
    this.on('updating', function (model, attrs, options) {
      return this.deepChanged('name', 'email', options)
        .then(function (hasDeepChanged) {
          if (hasDeepChanged[0]) {
            this.set('name_changed_at', new Date());
          }
          if (hasDeepChanged[1]) {
            this.set('email_changed_at', new Date());
          }
        });
    });
  }
});

You need to add bookshelf-deep-changed to the list of bookshelf's plugins when you require bookshelf:

var knex = require('knex')({
    /// knex initialization
  }),
  bookshelf = require('bookshelf')(knex);

bookshelf.plugin(require('bookshelf-deep-changed'));
1.0.0

9 years ago

0.2.0

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago