diff options
author | Yves Senn <yves.senn@gmail.com> | 2016-11-16 08:52:49 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2016-11-16 08:52:49 +0100 |
commit | 3b2346ea1393ad5deb049ae071116773c602ddc0 (patch) | |
tree | 9108c8bfbfef04907585eca6729a834a502fad4f | |
parent | c2c6b7be23126834b01273bfa95f90dac06513f6 (diff) | |
download | rails-3b2346ea1393ad5deb049ae071116773c602ddc0.tar.gz rails-3b2346ea1393ad5deb049ae071116773c602ddc0.tar.bz2 rails-3b2346ea1393ad5deb049ae071116773c602ddc0.zip |
docs, add `update_all` example with SQL fragment. [ci skip]
The relation method `update_all` allows you to pass a SQL fragment. The
functionality is already mentioned in the prose but the examples section
does not cover it.
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 8b30a48c1c..6f602e4a23 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -362,6 +362,9 @@ module ActiveRecord # # # Update all books that match conditions, but limit it to 5 ordered by date # Book.where('title LIKE ?', '%Rails%').order(:created_at).limit(5).update_all(author: 'David') + # + # # Update all invoices and set the number column to its id value. + # Invoice.update_all('number = id') def update_all(updates) raise ArgumentError, "Empty list of attributes to change" if updates.blank? |