Is there any way to set database columns to auto update a timestamp column on update? Can I do something like t.column "timestamp", :datetime, :default => :current_time, :null => false, :on_update => :current_timestamp or do i need to just use custom sql like sql = "ALTER TABLE `table` CHANGE `timestamp` `timestamp` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP" exectue sql Any help is appreciated. Thanks. -- Posted via http://www.ruby-forum.com/.
> Is there any way to set database columns to auto update a timestamp > column on update?If you simply name your column ''updated_at'', Rails will update it automatically when its parent record is updated. FYI, ''updated_at'' is a magic column name(tm). For some others, see http://wiki.rubyonrails.com/rails/pages/MagicFieldNames - Danny -- Posted via http://www.ruby-forum.com/.
Andrew Kortina
2006-Jun-12 21:23 UTC
[Rails] Re: on_update current_timestamp in Migrations
Daniel Burkes wrote:>> Is there any way to set database columns to auto update a timestamp >> column on update? > > If you simply name your column ''updated_at'', Rails will update it > automatically when its parent record is updated. > > FYI, ''updated_at'' is a magic column name(tm). For some others, see > > http://wiki.rubyonrails.com/rails/pages/MagicFieldNames > > - DannyWow, that''s excellent. The more I learn about rails, the more I love it. Thank you! -- Posted via http://www.ruby-forum.com/.
Seemingly Similar Threads
- Sqlite3 migration and CURRENT_TIMESTAMP
- how can I use a the current_timestamp feature of a database without a magial column
- migrations :timestamp becomes :datetime in mySql
- Confusion with counter and single table inheritance
- how to insert Current DateTime value into database?