diff options
author | Rodrigo Navarro <rnavarro1@gmail.com> | 2011-02-20 22:22:52 -0300 |
---|---|---|
committer | Rodrigo Navarro <rnavarro1@gmail.com> | 2011-02-20 22:22:52 -0300 |
commit | 62fd3346843845cbf0266e8eab895d7cf285c24e (patch) | |
tree | bd69df352da643063b66d99dbfd4198204cc9bb2 /activerecord/lib | |
parent | 4da0157aaffef6063d5ad2984c4a4e472f15f0d5 (diff) | |
download | rails-62fd3346843845cbf0266e8eab895d7cf285c24e.tar.gz rails-62fd3346843845cbf0266e8eab895d7cf285c24e.tar.bz2 rails-62fd3346843845cbf0266e8eab895d7cf285c24e.zip |
Adding new examples for update_all method
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 6 |
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) |