Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequelize: update by column it's old value

i am trying to update a set of data using Sequelize by this query

Users.update({
    flag: 'flag & ~ 2'
} , {
    where : {
        id :{
            gt : 2
        }
    }
})

the generated query is

UPDATE `users` SET `flag`='flag & ~ 2' WHERE id > 2

But is should be

UPDATE `users` SET `flag`=flag & ~ 2 WHERE id > 2

so my question is how can i update data by by it's old value

Regards

like image 976
hussam Avatar asked Apr 09 '15 09:04

hussam


1 Answers

You should be able to do this via:

Users.update({
    flag: sequelize.literal('flag & ~ 2')
} , {
    where : {
        id :{
            gt : 2
        }
    }
});
like image 134
Matthias Dietrich Avatar answered Sep 30 '22 12:09

Matthias Dietrich