保存了mongoid替换铁轨(触摸:false)



Ruby on Rails active_record从版本5开始,在将记录保存到数据库时具有选项{touch:false}。https://blog.bigbinary.com/2016/05/09/rails-5-allows-updating-without-updating-timestamps.html

我找不到这个(或类似的(选项是否也在mongoid中实现。{touch:false}似乎不起作用。

由TheR

否:(

我不认为是这样,帕尔!

我是如何检查的:

  1. 下载源代码并使用grep进行搜索

git clone https://github.com/mongodb/mongoid.git

持久化实例方法都使用选项Hash,我看不到任何关于touch选项的提及。

  1. 在上搜索文档https://docs.mongodb.com/mongoid/7.1/tutorials/mongoid-persistence/index.html

一种潜在的解决方法

这是我快速键入的伪代码,因为我不知道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) 

回答我自己的问题。

Mongoid有一个永恒的方法,它正是我想要的。

my_document.timeless.save

我还向mongoid团队提出了一个请求,看起来上面的功能将围绕mongoid v8实现。

由TheR

最新更新