Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding new examples for update_all method

  • Loading branch information...
commit 26a50689c9079087d5323d45921d3af958c03eb4 1 parent b39766f
Rodrigo Navarro reu authored bowsersenior committed
Showing with 6 additions and 0 deletions.
  1. +6 −0 activerecord/lib/active_record/relation.rb
6 activerecord/lib/active_record/relation.rb
View
@@ -176,6 +176,12 @@ def scoping
#
# # Update all books that match conditions, but limit it to 5 ordered by date
# Book.update_all "author = 'David'", "title LIKE '%Rails%'", :order => 'created_at', :limit => 5
+ #
+ # # Conditions from the current relation also works
+ # Book.where('title LIKE ?', '%Rails%').update_all(:author => 'David')
+ #
+ # # The same idea applies to limit and order
+ # Book.where('title LIKE ?', '%Rails%').order(:created_at).limit(5).update_all(:author => 'David')
def update_all(updates, conditions = nil, options = {})
if conditions || options.present?
where(conditions).apply_finder_options(options.slice(:limit, :order)).update_all(updates)
Please sign in to comment.
Something went wrong with that request. Please try again.