LoginSignup
3
0

More than 5 years have passed since last update.

Rails + Mongoid で Timestamps を更新せずに保存

Posted at

Rails + Mongoid でTimestampを更新したくない

ActiveRecord 使ってるとModel.record_timestamps = falseで対処できるのだけど、
Mongoidの場合がちょっと検索しても出てこなかったのでまとめ。

実装

Person クラスのインスタンスの person というオブジェクトを例にすると以下のように、

if person.timelss.save
 person.clear_timeless_option
end

という感じでインスタンス毎に使うようです。
簡単。

ドキュメント

詳しくは以下参照。
http://mongoid.org/en/mongoid/v3/extras.html#timestamps

3
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0