Blackjack
Blackjack

Reputation: 1065

Sequelize: Can't do update on column UpdatedAt

I've an express apps that use Sequelize as ORM. Basically, columns createdAt and updatedAt auto-generated by Sequelize. Every time I do update data in a row except column updatedAt, the column updatedAt will be updated based on current datetime. But when I'm trying to update the column updatedAt, it didn't update the value of column updatedAt. I've several way based on docs and another issue in so, like:

value.set('createdAt', new Date());
   value.save().then(value1 => {
            console.log('UpdatedAt has been updated');
            next();
   }
)

and

    Token.update(
    {
        updatedAt: new Date
    },
    {
        where: {
            token_id: token
        }
    }
).then(value1 => {
        console.log('Token UpdatedAt has been updated');
    }
)

But non of both work.

Anyone know why? and how to fix that. Thankyou.

Upvotes: 2

Views: 2937

Answers (1)

Vivek Doshi
Vivek Doshi

Reputation: 58533

The short and simple way for this is :

Token.changed('updatedAt', true); // <--- This will update the updatedAt field

Upvotes: 2

Related Questions