Skip to content

Commit

Permalink
docs, add update_all example with SQL fragment. [ci skip]
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
senny committed Nov 16, 2016
1 parent 6a522a0 commit a7d03b2
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions activerecord/lib/active_record/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ def scoping
#
# # 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?

Expand Down

0 comments on commit a7d03b2

Please sign in to comment.