开发者

ruby activerecord how to use alternate updated_at column

I am trying to use Rails3 with an existing db schema. The timestamp fields updated_at and created_at need to be mapped to created and modified on the db.

Is there a way to tell activerecord to use alternate column names?

Thanks in advance, Chris

EDIT

Could it be done by having this in a file in the model directory:

module ActiveRecord

  module Timestamp
    def timestamp_attributes_for_update #:nodoc:
      [:modified, :updated_on]
    end

    def timestamp_attributes_for_create #:nodoc:
 开发者_StackOverflow社区     [:created, :created_on]
    end
  end

end


I don't think there is a way to do that without overriding timestamp_attributes_for_update in ActiveRecord:: Timestamp.

A simple workaround would be to use a before_update callback in the model.

before_update :set_modified_time

private
  def set_modified_time
    self.modified = Time.now
  end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜