Permalink
Browse files

Adding new examples for update_all method

  • Loading branch information...
1 parent b39766f commit 26a50689c9079087d5323d45921d3af958c03eb4 @reu reu committed with bowsersenior Feb 21, 2011
Showing with 6 additions and 0 deletions.
  1. +6 −0 activerecord/lib/active_record/relation.rb
@@ -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)

0 comments on commit 26a5068

Please sign in to comment.