When creating a new record, rails does not use the default DB values
that are functions. For example, ``col1 timestamp with time zone not
null default NOW().'' Instead, Rails sets col1 to "NULL" on an INSERT
and my Postgresql DB complains and fails.
Using magical column names, such as created_at is not an option. I want
the DB to set the timestamps, not the Rails application servers.
If Rails would just leave these untouched/unset/nil columns out of the
INSERT statement, everything would be fine because the DB would set the
values using its defaults. I have tried removing the instance variables
using the method remove_instance_variables and have tried removing
elements in the attributes hash using attr_accessible, that correspond
to the nil columns; nothing works. Also, I don't want to resort to
custom SQL queries.
Many people have mentioned this issue on the web, but I cannot find a
resolution. Also, at least three tickets, #4540, #2257, #3913, on
dev.rubyonrails.org/ticket/ have mentioned this same thing. It seems
this issue has been in limbo between fixed and broken.
I have searched through
active_record/connection_adapters/postgresql_adapter.rb in my Rails
Edge for parsings of "now" (DB function), but came up empty. It seems
that the code that fixed this in the tickets I mentioned above was for
Rails 1.1. Unfortunately, it looks like this patch was removed
Suggestions and insights will be greatly appreciated.