diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-06-17 12:19:27 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-06-17 16:00:48 -0600 |
commit | d5d734939864fa871daf8cef72b638aebf3b0f37 (patch) | |
tree | 2139341a41e21021b5f28b5c396c0dd792439bae /activerecord/lib/active_record/type/date_time.rb | |
parent | 63b347df427ed2189fac7e75e36a3a4b9f6c2a68 (diff) | |
download | rails-d5d734939864fa871daf8cef72b638aebf3b0f37.tar.gz rails-d5d734939864fa871daf8cef72b638aebf3b0f37.tar.bz2 rails-d5d734939864fa871daf8cef72b638aebf3b0f37.zip |
Move array database type casting to the Array type
The case where we have a column object, but don't have a type cast
method involves type casting the default value when changing the schema.
We get one of the column definition structs instead. That is a case that
I'm trying to remove overall, but in the short term, we can achieve the
same behavior without needing to pass the adapter to the array type by
creating a fake type that proxies to the adapter.
Diffstat (limited to 'activerecord/lib/active_record/type/date_time.rb')
-rw-r--r-- | activerecord/lib/active_record/type/date_time.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/type/date_time.rb b/activerecord/lib/active_record/type/date_time.rb index 560d63c101..5f19608a33 100644 --- a/activerecord/lib/active_record/type/date_time.rb +++ b/activerecord/lib/active_record/type/date_time.rb @@ -7,6 +7,16 @@ module ActiveRecord :datetime end + def type_cast_for_database(value) + zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal + + if value.acts_like?(:time) + value.send(zone_conversion_method) + else + super + end + end + private def cast_value(string) |