5.0.2: Attribute change data type after save and change back on reload.

13 views
Skip to first unread message

Espen Antonsen

unread,
Mar 28, 2017, 12:34:33 PM3/28/17
to Ruby on Rails: Core
I'm using PostgreSQL time data types. One column is an array. Both fields have the same issue.

My problem is that an attribute changes data type after the object is saved. From Time before being saved to ActiveRecord::Type::Time::Value after save. Reloading the object gives Time again.

Prior to Rails 5.0.2 the data type was changed on a standard column, but not on the time array column. It's good that it is consistent, but shouldn't the attribute return the same data type at all times?

g = GoodTime.new(one_time:"10:00", many_times:["15:30", "17:45"])
=> #<GoodTime id: nil, one_time: "2000-01-01 10:00:00", many_times: [2000-01-01 15:30:00 UTC, 2000-01-01 17:45:00 UTC]>
g.one_time.class
=> Time
g.many_times.first.class
=> Time
g.save
=> true
g.one_time.class
=> ActiveRecord::Type::Time::Value
g.many_times.first.class
=> ActiveRecord::Type::Time::Value
g.reload
=> #<GoodTime id: 6, one_time: "2000-01-01 10:00:00", many_times: [2000-01-01 15:30:00 UTC, 2000-01-01 17:45:00 UTC]>
irb(main):020:0> g.one_time.class
=> Time
irb(main):021:0> g.many_times.first.class
=> Time

Reply all
Reply to author
Forward
0 new messages