3 ms·
// updates the whole table, ignoring conditions db.Model(<table>).Where(<conditions>).Updates(<values>) // updates the rows matching conditions db.M
by mleonhard 5y ago
// updates the whole table, ignoring conditions
db.Model(<table>).Where(<conditions>).Updates(<values>)
// updates the rows matching conditions
db.Model(<table>).Updates(<values>).Where(<conditions>)
This is a massive footgun in Gorm. Don't use tools that help you make catastrophic errors.
- ufmace 5y agoYeah wow. I don't understand why any ORM would ever let you do that. I don't think I've ever heard of a case where someone actually wanted to update every row in a table from application code. IMO, any decent ORM should block that entirely and force you to drop to SQL if you actually want to do it, or make you call some obnoxiously named function, like: db.Model(<table>).YesIReallyDoWantToUpdateEveryRowOnTheTable().Update(<values>)