Home > Blockchain >  Sequelize: Increment and updated_at in same method
Sequelize: Increment and updated_at in same method

Time:06-22

Using Sequelize is there a way to increment a value and also update the updated_at column in the same call? I would assume there is a way to do this as using the increment method is updating the table so the updated_at column should be updated at the same time, without having to waste a second call only to update the updated_at column.

    await account.increment(
        ["balance"],
        {
          by: updateAmount,
        },
        { transaction: transaction }
      );

      await account.update(
        {
          updated_at: new Date()
        },
        { transaction: transaction }
      );

The docs dont seem to mention it

CodePudding user response:

No. As the docs say increment is a convenience method. If you need to do more then incrementing then you have to use the update method.

  • Related