0

I have model call "point", I want to update field "updated" on point in every action update. So, I make hook boforeUpdate to modify updated with new Date(). In result callback is true, and updated fied is a new datetime. But not updated on db, the field still old datetime. My code:

var app = require('../../../server.js'),
point = app.models.point;

point.beforeUpdate = function(next) {
  var app = this;
  app.updated = new Date();
  next();
}
allfix
  • 52
  • 1
  • 5

1 Answers1

1

beforeUpdate callback takes two parameters: a callback (which is next in your example) and an object (your point instance)

var app = require('../../../server.js'),
point = app.models.point;

point.beforeUpdate = function(next, pt) {
  pt.updated = new Date();
  next();
}

Assuming that your code lies in app/models/point.js it can be simplified to:

module.exports = function(Point) {
  Point.beforeUpdate = function(next, point) {
    point.updated = new Date();
    next();
  }
};
Warszk
  • 136
  • 3