From 3b2346ea1393ad5deb049ae071116773c602ddc0 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Wed, 16 Nov 2016 08:52:49 +0100 Subject: 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. --- activerecord/lib/active_record/relation.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'activerecord/lib/active_record/relation.rb') 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? -- cgit v1.2.3