我希望将udtraekkes (datetime)设置为NULL,用于udtraekkesinfo不等于NULL或NIL的所有记录。我的型号叫Konkurrencer。
如何在rails控制台中更新所有konkurrencers记录?
发布于 2012-03-25 06:20:37
我认为你需要update_all
方法。Documentation
发布于 2012-03-25 06:31:07
Konkurrencer.update_all({udtraekkes: nil},"udtraekkesinfo不为空“)
发布于 2017-08-08 14:37:54
在Rails 4.0.13中,我使用此语法进行了测试,它在rails 3中可能会为您做同样的事情。
Model.where(conditions).update_all(:column_name=> nil)
where conditions are filtered condition to fetch the each record and update_all will operate on those record, you can update one or more column based on your requirement.
对于您的需求,代码将是。
Konkurrencer.where(:udtraekkes=> nil).update_all(:udtraekkes=> nil)
https://stackoverflow.com/questions/9856067
复制相似问题