我有接下来的三个模型:
class School < ActiveRecord::Base
audited
has_associated_audits
has_many :subjects, dependent: :destroy
end
class Subject < ActiveRecord::Base
audited associated_with: :school
has_associated_audits
has_many :attachments, as: :attachable, dependent: :destroy
end
class Attachment < ActiveRecord::Base
audited associated_with: :attachable
belongs_to :attachable, polymorphic: true
end
基本上, Aschool
有很多subjects
,每个subject
都有很多attachments
(attachment
模型是多态的,因为它也用于其他模型,以防万一它很重要......)
问题是审计没有像我预期的那样工作。我创建了一所学校,然后为该学校创建了一个主题,然后我为该主题添加了附件。这是我从控制台得到的:
School.last.associated_audits # => returns only changes on Subjects, not on subject's attachments.
Subject.last.associated_audits # => returns only changes associated to its attachments
但我也需要School.last.associated_audits
包括附件审核的更改。
有任何想法吗?