标签: ruby-on-rails rails-models
我们可以按条件更新记录而不先检查记录吗?
答案 0 :(得分:5)
是的,方法是update_all。
# Update all books with 'Rails' in their title Book.update_all "author = 'David'", "title LIKE '%Rails%'"
http://apidock.com/rails/ActiveRecord/Relation/update_all