Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update column value with existing column value in sequelize

like:

update user.age = user.age+1 where id=123

try:

models.User.update({age:sequelize.col('age')+1},{where:{id:123}}).success()...

What should I do?

like image 718
胡雪亮 Avatar asked Sep 10 '25 19:09

胡雪亮


1 Answers

this way you can update with the existing value.

Sequelize.literal('no_of_sub_categorys + 1')

sample code :

CountModel.update({
    no_of_sub_categorys: Sequelize.literal('no_of_sub_categorys + 1')
 }, {
      where: {
      category_id: requestData.parent_id,
      active: 1
    }
 })
like image 131
Sushil Avatar answered Sep 13 '25 09:09

Sushil