Configure legacy timestamp attributes in Activerecord
In ActiveRecord, when working with legacy database and the existing database
uses different fields for last_update
and created_at
, how do you specify the
correct column names for ActiveRecord to properly record timestamps?
# in your config/initializers directory, create a new file
# `active_record_patch.rb`
# overload
module ActiveRecord
module Timestamp
private
def timestamp_attributes_for_create #:nodoc:
[:created_at, :created_on, :create_date, :post_date]
end
def timestamp_attributes_for_update #:nodoc:
[:modtime, :updated_on, :modified_at, :updated_at, :last_update]
end
end
end