Audited-activerecord gem无法正常工作以进行多态关联

时间:2016-03-29 16:55:38

标签: ruby-on-rails ruby activerecord audit

我想对嵌套关联进行审核,比如我有

用户has_many地址,即

HomeAddress或OfficeAddress

现在,如果我只有一个表地址,并且我使用了类型和id来区分它们。在这种情况下,如果我对User使用associated_audits,那么它将只生成一个审计记录,每当我再次更新记录时,它只是替换它上一次审核与最后一次审核。

以下是模特协会:

class Patient <  ActiveRecord::Base

  devise :database_authenticatable, :registerable, :recoverable, :rememberable,
         :trackable, :validatable, :confirmable, request_keys: [:subdomain]

  has_one :home_address,-> { where(addr_type: 'home') },class_name: 'Address'
  has_one :office_address,-> { where(addr_type: 'office') }, class_name: 'Address'
  has_associated_audits

  accepts_nested_attributes_for :home_address, allow_destroy: true
  accepts_nested_attributes_for :office_address,  allow_destroy: true
end


class Address < ActiveRecord::Base

  belongs_to :patient
  audited

end

1 个答案:

答案 0 :(得分:1)

class Address < ActiveRecord::Base
  belongs_to :patient
  audited associated_with: :patient
end

class Patient <  ActiveRecord::Base
  has_many :addresses
  has_associated_audits
end