From cfa1df4b07bee5b2bbcbf9edd2ac287b4fb23c18 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Mon, 25 Apr 2016 19:35:16 +0900 Subject: update record specified in key `#first_or_initialize` does not use attributes to data acquisition. Therefore, there is a possibility of updating the different record than the one specified in the key, I think this is not expected behavior. --- activerecord/lib/active_record/internal_metadata.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/internal_metadata.rb') diff --git a/activerecord/lib/active_record/internal_metadata.rb b/activerecord/lib/active_record/internal_metadata.rb index 81db96bffd..17a5dc1d1b 100644 --- a/activerecord/lib/active_record/internal_metadata.rb +++ b/activerecord/lib/active_record/internal_metadata.rb @@ -19,7 +19,7 @@ module ActiveRecord end def []=(key, value) - first_or_initialize(key: key).update_attributes!(value: value) + find_or_initialize_by(key: key).update_attributes!(value: value) end def [](key) -- cgit v1.2.3