aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodrigo Navarro <rnavarro1@gmail.com>2011-02-20 22:22:52 -0300
committerMani Tadayon <bowsersenior@gmail.com>2011-02-21 13:44:20 -0800
commit26a50689c9079087d5323d45921d3af958c03eb4 (patch)
treec58e23a9954f391c7da65ed9dd776e0a7362233f
parentb39766fda560bb911bd4f8247101d641d4f60958 (diff)
downloadrails-26a50689c9079087d5323d45921d3af958c03eb4.tar.gz
rails-26a50689c9079087d5323d45921d3af958c03eb4.tar.bz2
rails-26a50689c9079087d5323d45921d3af958c03eb4.zip
Adding new examples for update_all method
-rw-r--r--activerecord/lib/active_record/relation.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 948f33f24e..c6cd8891e3 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -176,6 +176,12 @@ module ActiveRecord
#
# # 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)