PDA

View Full Version : Hint : Take Advantage of created_on and updated_on


rob
June 4th, 2005, 01:21 AM
While some Rails tutorials out there cover this issue, others don't. Before you make a column in your database to keep track of when the row was created, or updated, why not take advantage of created_on and updated_on that Rails makes for you?

Don't repeat yourself, or Ruby :)

For reference, here is the SQL schema of the two columns it makes and maintains for you:

`created_on` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`updated_on` timestamp NOT NULL default '0000-00-00 00:00:00',