如何使用Mongoid History gem跟踪数组中的更改?我有一系列问题。它看起来像这样
Questions = [ {"intro" => "Intro: 1", "name" => "Name: 1"}, {"intro" => "Intro: 2", "name" => "Name: 2"} ]
这是我的代码
class Script
include Mongoid::History::Trackable
field :name, type: String
field :type, type: String
field :questions, type: Array, default: []
track_history on: [ :type, :name, :questions ], track_create: true, track_update: true, track_destory: true
end
class Question
include Mongoid::History::Trackable
field :intro, type: String
field :name, type: String
track_history(
on: :fields,
scope: :script,
track_create: true,
track_update: true,
track_destroy: true
)
end
当我进行更改时,它会为我提供包含所有信息的数组,而不仅仅是更改的名称或介绍。我不希望出于各种原因将问题嵌入到脚本中。在我的情况下,最好的方法是为它创建一个字段。