I'm using sequelize 2.0.0 with PostgreSQL. I would like to know if it's possible to update the field 'updated_at' of a model with one method. If yes, how can I achieve that?
For instance, in others frameworks, like Laravel, you have model.touch() to automatically update the 'updated_at' of a model.
I've already tried to use model.save() but as the sequelize doc says, calling this method without attributes does nothing. Also, in the doc, I didn't find anything that allow me to do what I need to do simply.
Thanks in advance for help.
Edit:
To give an example of what I'm trying to achieved, I've already had an instance of my model:
Model.findById(1).then(function(myInstance){
[...]
myInstance.update() //here, I didn't change any attributes of myInstance and I would like to update the field udpated_at without doing another query.
[...]
}):
The question is : How can I update the field updated_at of my previous instance with one method?
To update an instance value, you can use instance.set(key, value, [options]).
myInstance.set('updatedAt', new Date());
myInstance.save().then(function() {
// my nice callback stuff
});
The sequelize docs have a good example of doing an update query if you don't have an instance:
Post.update({
updatedAt: null,
}, {
where: {
deletedAt: {
$ne: null
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With