npm

Need private packages and team management tools?Check out npm Orgs. »

bookshelf-deep-changed

1.0.0 • Public • Published

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'));

install

npm i bookshelf-deep-changed

Downloadsweekly downloads

18

version

1.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
Report a vulnerability