Mongoid只使用created_at时间戳
问题描述:
有没有办法只为只读文档设置created_at时间戳?Mongoid只使用created_at时间戳
目前,我有以下消息类
class Message
include Mongoid::Document
include Mongoid::Timestamps
field :text, type: String
belongs_to :user, foreign_key: :user_id
embedded_in :conversation
end
它工作正常,但对于每封邮件,我用的updated_at领域浪费空间,这将永远是相同的created_at
答
通过此页面的时间戳部分。 https://docs.mongodb.com/mongoid/master/tutorials/mongoid-documents/
include Mongoid::Timestamps - created_at and updated_at.
include Mongoid::Timestamps::Created - created_at only.
include Mongoid::Timestamps::Updated - updated_at only.
ü甚至可以短名称
include Mongoid::Timestamps::Short - c_at and u_at.
include Mongoid::Timestamps::Created::Short - c_at only.
include Mongoid::Timestamps::Updated::Short - u_at only.
答
包括Mongoid::Timestamps::Created
而不是Mongoid::Timestamps
。
class Message
include Mongoid::Document
include Mongoid::Timestamps::Created
field :text, type: String
belongs_to :user, foreign_key: :user_id
embedded_in :conversation
end