[英]How to skip all callbacks except paper-trail when updating an ActiveRecord model using update_column method?
I am new to rails.我是新来的轨道。 I want to track the versions of my record using paper_trail gem but I am not able to do so when I use the update_columns method.
我想使用 paper_trail gem 跟踪我的记录版本,但是当我使用 update_columns 方法时我无法这样做。 I think overriding the update_columns method may help me but I don't know how exactly should I write the code?
我认为覆盖 update_columns 方法可能对我有帮助,但我不知道我应该如何编写代码?
How to skip all callbacks except paper-trail when updating an ActiveRecord model using update_column method?
使用 update_column 方法更新 ActiveRecord model 时,如何跳过除纸迹之外的所有回调? .. I use the update_columns method.
.. 我使用 update_columns 方法。
Per the Rails docs , the update_columns
method skips callbacks.根据Rails 文档,
update_columns
方法会跳过回调。 This includes the callbacks installed by PT.这包括 PT 安装的回调。
I am new to rails.
我是新来的轨道。 ... I think overriding the update_columns method may help me..?
...我认为覆盖 update_columns 方法可能对我有帮助..?
If you're new to rails, you should not override core rails methods.如果您不熟悉 rails,则不应覆盖核心 rails 方法。
In descending order of preference:按偏好降序排列:
update
instead of update_columns
.update
而不是update_columns
。 But, you want to skip a proper subset of callbacks.touch
the record, and PT will record a Version
in which only updated_at
changed.touch
记录,PT 将记录一个只有updated_at
发生变化的Version
。 If you only need object
and not object_changes
, this is sufficient.object
而不需要object_changes
,这就足够了。PaperTrail::Version.create
just like any other model.PaperTrail::Version.create
。 This is public API, but you're responsible for passing the correct attributes.PaperTrail::RecordTrail#record_update
.PaperTrail::RecordTrail#record_update
。 This is private API and is subject to change at any time without warning.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.