Is there anyway to set only the created_at timestamp for read-only documents?
I currently have the following message class
class Message
include Mongoid::Document
include Mongoid::Timestamps
field :text, type: String
belongs_to :user, foreign_key: :user_id
embedded_in :conversation
end
It works ok, but for every message I'm wasting space with the updated_at field, which will always be the same as created_at
Go through Timestamping section of this page.
include Mongoid::Timestamps - created_at and updated_at.
include Mongoid::Timestamps::Created - created_at only.
include Mongoid::Timestamps::Updated - updated_at only.
You can even have short names
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.
Include Mongoid::Timestamps::Created
instead of 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With