1

我们可以在不先检查记录的情况下按条件更新记录吗?

4

1 回答 1

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

于 2010-12-01T08:34:12.560 回答