daisy
daisy

Reputation: 23581

Avoid Where phrase with gorm

I'm trying to update every record in a table:

sqlDB.Table("task").Where("1=1").Update("status", 1)

And I can't avoid the 1=1 where condition. Is that the right way to do it?

Upvotes: 0

Views: 530

Answers (2)

d1ss0nanz
d1ss0nanz

Reputation: 9

According to https://gorm.io/docs/update.html#Block-Global-Updates

This should work:

db.Session(&gorm.Session{AllowGlobalUpdate: true}).Model(&User{}).Update("name", "jinzhu")

Upvotes: 1

O. Jones
O. Jones

Reputation: 108841

Yes. 1=1 is a widely recognized always-true WHERE clause. Go for it.

Upvotes: 1

Related Questions