diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2016-12-08 13:41:36 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-08 13:41:36 -0500 |
commit | 6e948f480118bceb66b72a53874b800fbda05327 (patch) | |
tree | ef2e5b11c1ebb0f8e35125064c86bef8dcff88c0 /activerecord/lib/active_record | |
parent | 0d20530e5edfd7d00fbc2a38ef5f87eca6ccc924 (diff) | |
parent | 44dc4f6645e12ddd5cf927bca0675a5b44d55cbd (diff) | |
download | rails-6e948f480118bceb66b72a53874b800fbda05327.tar.gz rails-6e948f480118bceb66b72a53874b800fbda05327.tar.bz2 rails-6e948f480118bceb66b72a53874b800fbda05327.zip |
Merge pull request #26529 from prathamesh-sonpatki/fix-alias-attribute-issue
Check whether the current attribute being read is aliased or not before reading
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/read.rb | 7 | ||||
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/write.rb | 8 |
2 files changed, 13 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb index 30f7750884..5448ebc165 100644 --- a/activerecord/lib/active_record/attribute_methods/read.rb +++ b/activerecord/lib/active_record/attribute_methods/read.rb @@ -48,7 +48,12 @@ module ActiveRecord # it has been typecast (for example, "2004-12-12" in a date column is cast # to a date object, like Date.new(2004, 12, 12)). def read_attribute(attr_name, &block) - name = attr_name.to_s + name = if self.class.attribute_alias?(attr_name) + self.class.attribute_alias(attr_name).to_s + else + attr_name.to_s + end + name = self.class.primary_key if name == "id".freeze _read_attribute(name, &block) end diff --git a/activerecord/lib/active_record/attribute_methods/write.rb b/activerecord/lib/active_record/attribute_methods/write.rb index f65c297e01..0022d526a4 100644 --- a/activerecord/lib/active_record/attribute_methods/write.rb +++ b/activerecord/lib/active_record/attribute_methods/write.rb @@ -29,7 +29,13 @@ module ActiveRecord # specified +value+. Empty strings for Integer and Float columns are # turned into +nil+. def write_attribute(attr_name, value) - write_attribute_with_type_cast(attr_name, value, true) + name = if self.class.attribute_alias?(attr_name) + self.class.attribute_alias(attr_name).to_s + else + attr_name.to_s + end + + write_attribute_with_type_cast(name, value, true) end def raw_write_attribute(attr_name, value) # :nodoc: |