aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/persistence.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-01-02 06:03:24 +0900
committerRyuta Kamizono <kamipo@gmail.com>2019-01-02 06:23:52 +0900
commit4c05434973fde5f6dcc7dd58d360be13e1f02a80 (patch)
tree2acbbc6cd6ed19744beea6f1798f8d6a796c2662 /activerecord/lib/active_record/persistence.rb
parent600a66f60c76cb2d32fbf7abe4e37d509fdade47 (diff)
downloadrails-4c05434973fde5f6dcc7dd58d360be13e1f02a80.tar.gz
rails-4c05434973fde5f6dcc7dd58d360be13e1f02a80.tar.bz2
rails-4c05434973fde5f6dcc7dd58d360be13e1f02a80.zip
Restore an ability that class level `update` without giving ids
That ability was introduced at #11898 as `Relation#update` without giving ids, so the ability on the class level is not documented and not tested. c83e30d which fixes #33470 has lost two undocumented abilities. One has fixed at 5c65688, but I missed the ability on the class level. Removing any feature should not be suddenly happened in a stable version even if that is not documented. I've restored the ability and added test case to avoid any regression in the future. Fixes #34743.
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r--activerecord/lib/active_record/persistence.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index 7bf8d568df..c2b60610ce 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -96,11 +96,13 @@ module ActiveRecord
# When running callbacks is not needed for each record update,
# it is preferred to use {update_all}[rdoc-ref:Relation#update_all]
# for updating all records in a single query.
- def update(id, attributes)
+ def update(id = :all, attributes)
if id.is_a?(Array)
id.map { |one_id| find(one_id) }.each_with_index { |object, idx|
object.update(attributes[idx])
}
+ elsif id == :all
+ all.each { |record| record.update(attributes) }
else
if ActiveRecord::Base === id
raise ArgumentError,