问题描述
从版本5开始,将记录保存到数据库时,Ruby on Rails active_record具有选项{touch:false}。https://blog.bigbinary.com/2016/05/09/rails-5-allows-updating-without-updating-timestamps.html
我也找不到这个(或类似的)选项是否也用mongoid实现。 {touch:false}似乎无效。
作者 TheR
解决方法
否:(
我不认为它能帮上忙!
我如何检查:
- 下载源代码并使用
grep
搜索。
git clone https://github.com/mongodb/mongoid.git
持久性实例方法都使用选项Hash,我看不到touch
选项的任何内容。
可能的解决方法
这是我快速键入的伪代码,因为我从内存中不知道Mongoid的DSL,它基于ActiveRecord。
object = Object.find(1)
update = object.updated_at
object.update(update_the_object: :attributes_you_want_to)
# Use a method that doesn't update timestamps automatically to,well,update the timestamps.
object.update_column(updated_at: update)