Class: ActiveRecord::ConnectionAdapters::TableDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/mysql/search/templates/config/initializers/active_record_ext.rb

Overview

Overrides the ‘timestamps` method in `TableDefinition` to use MySQL’s ‘DATETIME ON UPDATE CURRENT_TIMESTAMP` for the `updated_at` column. This allows the `updated_at` column to automatically update its value whenever the row is updated.

Instance Method Summary collapse

Instance Method Details

#timestamps(**options) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/generators/mysql/search/templates/config/initializers/active_record_ext.rb', line 27

def timestamps(**options)
  options[:null] = false if options[:null].nil?

  options[:precision] = 6 if !options.key?(:precision) && @conn.supports_datetime_with_precision?

  column(:created_at, :datetime, **options)
  column(:updated_at, 'DATETIME ON UPDATE CURRENT_TIMESTAMP', **options)
end