I came across this idiosyncrasy while testing my validations. With a migration defined as follows:
create_table :time_windows do |t|
t.datetime :window_begin, :null => true
t.datetime :window_end, :null => true
end
in irb
>> t = TimeWindow.new({:window_begin => Time.now, :window_end => "not a time"})
=> #<TimeWindow id: nil, window_begin: "2010-07-29 15:54:07", window_end: nil>
My question is, why ActiveRecord interprets "not a time" as nil rather than just setting :window_end = "not a time"? The same translation-to-nil happens when you set :window_end to an int as well.
The reason this is a problem for me is if someone tries to save a non Time value in the :window_end (or :window_start) column, I'd like an error to be thrown, but that will not be the case here.
Thanks.