【问题标题】:Has mongoid replacement for rails save(touch: false)有轨道保存的 mongoid 替代品(触摸:假)
【发布时间】:2020-08-25 12:07:33
【问题描述】:

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

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

通过 该R

【问题讨论】:

    标签: ruby-on-rails mongoid


    【解决方案1】:

    没有:(

    我不认为它是朋友!

    我是如何检查的:

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

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

    可持久化的实例方法都使用选项哈希,我看不到任何提及 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) 
    

    【讨论】:

      猜你喜欢
      • 2013-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多