diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-06-15 16:44:42 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-15 16:44:42 -0400 |
commit | 703128dbfee9b8fca281b5accc22b2b4a37ce4df (patch) | |
tree | e1f5d95c59f078478b294ba189c36927a86187ce /activerecord/lib/active_record | |
parent | 053db5096287c0d3a9597bff3f669e32a64cc387 (diff) | |
parent | 2e4fe3a4ada95d08a77ff4df5cbf49ada0a10f6d (diff) | |
download | rails-703128dbfee9b8fca281b5accc22b2b4a37ce4df.tar.gz rails-703128dbfee9b8fca281b5accc22b2b4a37ce4df.tar.bz2 rails-703128dbfee9b8fca281b5accc22b2b4a37ce4df.zip |
Merge pull request #29464 from eugeneius/raw_write_attribute
Don't map id to primary key in raw_write_attribute
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/write.rb | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/write.rb b/activerecord/lib/active_record/attribute_methods/write.rb index fe0e01db28..75c5a1a600 100644 --- a/activerecord/lib/active_record/attribute_methods/write.rb +++ b/activerecord/lib/active_record/attribute_methods/write.rb @@ -35,11 +35,15 @@ module ActiveRecord attr_name.to_s end - write_attribute_with_type_cast(name, value, true) + name = self.class.primary_key if name == "id".freeze && self.class.primary_key + @attributes.write_from_user(name, value) + value end def raw_write_attribute(attr_name, value) # :nodoc: - write_attribute_with_type_cast(attr_name, value, false) + name = attr_name.to_s + @attributes.write_cast_value(name, value) + value end private @@ -47,19 +51,6 @@ module ActiveRecord def attribute=(attribute_name, value) write_attribute(attribute_name, value) end - - def write_attribute_with_type_cast(attr_name, value, should_type_cast) - attr_name = attr_name.to_s - attr_name = self.class.primary_key if attr_name == "id" && self.class.primary_key - - if should_type_cast - @attributes.write_from_user(attr_name, value) - else - @attributes.write_cast_value(attr_name, value) - end - - value - end end end end |