aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-08-29 13:46:02 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-08-31 02:56:32 +0900
commit5c656889a65e116cf0beb1a059df9d1072aa088f (patch)
tree7518079fa23a9247f36215c9349a5f50fe6854cc /activerecord/lib
parent8f2caec401c8e97d9eb1ea84d8263911c50e1ed6 (diff)
downloadrails-5c656889a65e116cf0beb1a059df9d1072aa088f.tar.gz
rails-5c656889a65e116cf0beb1a059df9d1072aa088f.tar.bz2
rails-5c656889a65e116cf0beb1a059df9d1072aa088f.zip
Just delegate `update` with ids on a relation to `klass.update`
This restores an ability that `update` with ids on a relation which is described at https://github.com/rails/rails/issues/33470#issuecomment-411203013. I personally think that the `update` with two arguments on a relation is not a designed feature, since that is totally not using a relation state, and also is not documented. But removing any feature should not be suddenly happened in a stable version even if that is not documented.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/relation.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 2d3e1eaa08..29a3ceab7d 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -375,8 +375,12 @@ module ActiveRecord
@klass.connection.update stmt, "#{@klass} Update All"
end
- def update(attributes) # :nodoc:
- each { |record| record.update(attributes) }
+ def update(id = :all, attributes) # :nodoc:
+ if id == :all
+ each { |record| record.update(attributes) }
+ else
+ klass.update(id, attributes)
+ end
end
def update_counters(counters) # :nodoc: