Reputation: 2879
I am using sequelize.js library as ORM in node development. When update a row using sequelize, 'updated_at' field changed to current time-stamp. I would like to know how can I prevent this ? Without changing 'updated_at' field I would like to update other fields using sequlize API, not running raw query.
Upvotes: 11
Views: 6883
Reputation: 151
According to http://docs.sequelizejs.com/class/lib/model.js~Model.html#static-method-update you can use the "silent" option to run an update query but not update the updateAt field.
options.silent Boolean
optional
default: false
If true, the updatedAt timestamp will not be updated.
myModelInstance.update(values, {
silent: true
})
Upvotes: 15
Reputation: 2998
In your model definition, you can turn timestamps off for specific fields.
If you want sequelize to handle timestamps, but only want some of them, or want your timestamps to be called something else, you can override each column individually:
var Foo = sequelize.define('foo', { /* bla */ }, {
// don't forget to enable timestamps!
timestamps: true,
// I don't want createdAt
createdAt: false,
// I want updatedAt to actually be called updateTimestamp
updatedAt: 'updateTimestamp'
// And deletedAt to be called destroyTime (remember to enable paranoid for this to work)
deletedAt: 'destroyTime',
paranoid: true
});
Otherwise, you can turn timestamps off and handle them manually per-update as you want to.
Upvotes: 0