Permalink
Browse files

Adding new examples for update_all method

  • Loading branch information...
1 parent 4da0157 commit 62fd3346843845cbf0266e8eab895d7cf285c24e @reu reu committed 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 62fd334

Please sign in to comment.