[英]how do I prevent Paper Trail from versioning on touch?
In many parts of my Rails 6 app I have belongs_to
associations with touch: true
which means that the updated_at
value of the parent object gets updated when the child is updated.在我的 Rails 6 应用程序的许多部分中,我的
belongs_to
关联都与touch: true
关联,这意味着父 object 的updated_at
值会在子更新时更新。
The problem is that I am using the Paper Trail gem to track changes in the data, but I don't want version records for the objects when they simply have been "touched" in this way.问题是我正在使用 Paper Trail gem 来跟踪数据中的更改,但是当对象只是以这种方式“触摸”时,我不希望对象的版本记录。
I've tried using the ignore
option on the updated_at
field like this:我试过在
updated_at
字段上使用ignore
选项,如下所示:
has_paper_trail ignore: [:updated_at]
which causes no version to be created when I do this当我这样做时,不会创建任何版本
my_object.update(updated_at: Time.current)
but it still creates a version when I do this但是当我这样做时它仍然会创建一个版本
my_object.touch
Paper Trail treats a "touch" operation separately from other updates. Paper Trail 将“触摸”操作与其他更新分开处理。 It can trigger versioning on any or all of these operations: create, destroy, update, touch.
它可以触发任何或所有这些操作的版本控制:创建、销毁、更新、触摸。
Use the on
option in order to specify a subset of operation that trigger versions that excludes 'touch'.使用
on
选项可指定触发不包括“触摸”的版本的操作子集。 Like this像这样
has_paper_trail on: [:create, :destroy, :update]
In the docs this is descibed in section 2.a.在文档中,这在第 2.a 节中进行了描述。 ( Choosing Lifecycle Events To Monitor )
( 选择要监控的生命周期事件)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.