Renaming the created_at, updated_at columns of ActiveRecord/Rails

前端 未结 10 680
囚心锁ツ
囚心锁ツ 2020-11-28 07:02

I want to rename the timestamp columns defined in timestamp.rb . Can the methods of timestamp.rb be overwritten? And what has to be done in the application that the module w

10条回答
  •  广开言路
    2020-11-28 07:58

    In Rails 6.0 the instance method timestamp_attributes_for_create does not exist anymore. This method got pushed up onto the class method level and is now private

    https://apidock.com/rails/v6.0.0/ActiveRecord/Timestamp/ClassMethods/timestamp_attributes_for_create

    This change was introduced with this commit https://github.com/rails/rails/commit/77ff9a0adbd1318b45203a76c64561b115245603

    You could still overwrite self.timestamp_attributes_for_create but I strongly suggest not to since the private API can be changed without further notice or bigger version bumps.

    For Rails 6 I don't see a given "Rails way" to define custom created_at / updated_at columns.

    I suggest following this answer https://stackoverflow.com/a/18197702/924050

提交回复
热议问题