From 9cbf54c81a46cc070f3997956c12915f39dbb46b Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Fri, 16 Sep 2016 19:21:56 +0530 Subject: Check whether the current attribute being read is aliased or not before reading - If aliased, then use the aliased attribute name. - Fixes #26417. --- activerecord/lib/active_record/attribute_methods/read.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/attribute_methods') 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 -- cgit v1.2.3 From 44dc4f6645e12ddd5cf927bca0675a5b44d55cbd Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Wed, 5 Oct 2016 22:04:33 +0530 Subject: Check whether the current attribute being write is aliased or not before writing - If aliased, then use the aliased attribute name. --- activerecord/lib/active_record/attribute_methods/write.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/attribute_methods') 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: -- cgit v1.2.3