2017-10-17 14 views
1

읽기 전용 문서의 created_at 타임 스탬프 만 설정해야합니까?몽고이드 만 사용됨 created_at timestamp

나는 현재 다음과 같은 메시지 클래스를 가지고

class Message 
    include Mongoid::Document 
    include Mongoid::Timestamps 

    field :text,  type: String 

    belongs_to :user, foreign_key: :user_id 
    embedded_in :conversation 
end 

그것은 확인을 작동하지만 항상 created_at과 동일하게 될 것입니다 나는 updated_at 필드에 공간을 낭비하고있어 모든 메시지에 대한

답변

2

이 페이지의 타임 스탬프 섹션으로 이동하십시오. 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. 

U 심지어 짧은 이름

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. 
을 가질 수 있습니다
1

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