diff options
-rw-r--r-- | activerecord/lib/active_record/attribute_methods.rb | 1 | ||||
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/read.rb | 9 |
2 files changed, 7 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 2a7a77777d..06b66b5195 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -64,6 +64,7 @@ module ActiveRecord return if attribute_methods_generated? superclass.define_attribute_methods unless self == base_class super(column_names) + column_names.each { |name| define_external_attribute_method(name) } @attribute_methods_generated = true end end diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb index 1548114580..9b3724777a 100644 --- a/activerecord/lib/active_record/attribute_methods/read.rb +++ b/activerecord/lib/active_record/attribute_methods/read.rb @@ -71,22 +71,25 @@ module ActiveRecord generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1 def __temp__ - #{internal_attribute_access_code(attr_name, cast_code)} + #{internal_attribute_access_code(attr_name, attribute_cast_code(attr_name))} end alias_method '#{attr_name}', :__temp__ undef_method :__temp__ STR + end + + private + def define_external_attribute_method(attr_name) generated_external_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1 def __temp__(v, attributes, attributes_cache, attr_name) - #{external_attribute_access_code(attr_name, cast_code)} + #{external_attribute_access_code(attr_name, attribute_cast_code(attr_name))} end alias_method '#{attr_name}', :__temp__ undef_method :__temp__ STR end - private def cacheable_column?(column) attribute_types_cached_by_default.include?(column.type) end |