diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-12-03 16:46:46 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-12-03 16:46:46 +0000 |
commit | 9c172b29311452a0e8eed42dfca64dbb5b168a94 (patch) | |
tree | 772a80571e77842d22759b015f60798d136db1ad /activerecord/lib/active_record/attribute_methods | |
parent | de24ed9f2d582096fcc5b83984f187c2a094e83a (diff) | |
download | rails-9c172b29311452a0e8eed42dfca64dbb5b168a94.tar.gz rails-9c172b29311452a0e8eed42dfca64dbb5b168a94.tar.bz2 rails-9c172b29311452a0e8eed42dfca64dbb5b168a94.zip |
Fix #3837.
We also need to time zone convert time zone aware attributes when
accessed via read_attribute, not only when via direct access.
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb index 236681096b..17cf34cdf6 100644 --- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb +++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb @@ -16,22 +16,16 @@ module ActiveRecord module ClassMethods protected - # Defined for all +datetime+ and +timestamp+ attributes when +time_zone_aware_attributes+ are enabled. - # This enhanced read method automatically converts the UTC time stored in the database to the time + # The enhanced read method automatically converts the UTC time stored in the database to the time # zone stored in Time.zone. - def internal_attribute_access_code(attr_name, cast_code) + def attribute_cast_code(attr_name) column = columns_hash[attr_name] if create_time_zone_conversion_attribute?(attr_name, column) - super(attr_name, "(v=#{column.type_cast_code('v')}) && #{cast_code}") - else - super - end - end + typecast = "v = #{super}" + time_zone_conversion = "v.acts_like?(:time) ? v.in_time_zone : v" - def attribute_cast_code(attr_name) - if create_time_zone_conversion_attribute?(attr_name, columns_hash[attr_name]) - "(v.acts_like?(:time) ? v.in_time_zone : v)" + "((#{typecast}) && (#{time_zone_conversion}))" else super end |