diff options
author | René van den Berg <rene.vandenberg@ogd.nl> | 2014-11-20 09:58:45 +0100 |
---|---|---|
committer | Rene van den Berg <rene.vandenberg@ogd.nl> | 2014-11-20 11:56:48 +0100 |
commit | 9ce105734d0b28de324c79a9e89906219f1555b7 (patch) | |
tree | f02ed6cb6af2b67b0fe1620cc76ff4f8cd2be6b9 /activerecord/lib | |
parent | 7839e27b4e467b5cf94e83555b9b6f0a4f6aaf8a (diff) | |
download | rails-9ce105734d0b28de324c79a9e89906219f1555b7.tar.gz rails-9ce105734d0b28de324c79a9e89906219f1555b7.tar.bz2 rails-9ce105734d0b28de324c79a9e89906219f1555b7.zip |
Explain that default_scope also influences update_all
This was not explicitly stated before and I needed to try it out to be
certain. A little explicit statement in the API docs might help here.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 460daf99bc..fc3306ee81 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -304,11 +304,12 @@ module ActiveRecord klass.current_scope = previous end - # Updates all records with details given if they match a set of conditions supplied, limits and order can - # also be supplied. This method constructs a single SQL UPDATE statement and sends it straight to the - # database. It does not instantiate the involved models and it does not trigger Active Record callbacks - # or validations. Values passed to `update_all` will not go through ActiveRecord's type-casting behavior. - # It should receive only values that can be passed as-is to the SQL database. + # Updates all records in the current scope (respecting the <tt>default_scope</tt>, <tt>where</tt>, + # <tt>limit</tt> and <tt>order</tt> specified) with details given. This method constructs a single SQL update_all + # statement and sends it straight to the database. It does not instantiate the involved models and it does not + # trigger Active Record callbacks or validations. Values passed to `update_all` will not go through + # ActiveRecord's type-casting behavior. It should receive only values that can be passed as-is to the SQL + # database. # # ==== Parameters # @@ -319,6 +320,12 @@ module ActiveRecord # # Update all customers with the given attributes # Customer.update_all wants_email: true # + # # Update all active accounts with the given attributes + # class Account < ActiveRecord::Base + # default_scope -> { where active: true } + # end + # Account.update_all(failed_logins: 0) + # # # Update all books with 'Rails' in their title # Book.where('title LIKE ?', '%Rails%').update_all(author: 'David') # |