First, if my understanding of what is happening is in error then
please forgive me.

I am given to understand that when a new AR model object is
initialized then AR obtains from the database, and I suppose caches
for further use, those columns that have defaults assigned and the
default value for each.

Consequently, when the save method is called on said model instance
then all of these columns are included in the generated SQL INSERT
statement and the default values are provided as values.  Why?  Surely
if any attribute with a default value is not specified in the INSERT
statement then the DBMS will handle the situation.  What is the point
of including columns that have not been referenced or set in the
current context in an INSERT statement?

This issue has bitten me because AR does not recognize 'infinity' as a
valid default value for a timestamp column.  Consequently AR is
attempting to insert a NULL into a column that has a NOT NULL
constraint.  This fails.  I cannot code around this because the
datetime class in Rails does not recognize 'infinity' as a valid
value.

ruby-1.8.7-p334 :003 > x.expected_at = 'infinity'
 => "infinity"
ruby-1.8.7-p334 :004 > x.save
ActiveRecord::StatementInvalid: PGError: ERROR:  null value in column
"expected_at" violates not-null constraint

To me, it seems both redundant and intrusive to handle column default
values as presently seems the case in AR.  If I do not wish to
explicitly set an attribute value in my application why then should
the framework do it for me regardless?

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to