我有接下来的三个模型:
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
基本上,A school
有很多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
包含附件审核更改。
有什么想法吗?
答案 0 :(得分:1)
虽然您无法从深层关联中检索审核,但您可以将审核分组在一起。例如:
h311o
我认为这应该为您提供school = School.find(params[:id])
audits = school.audits + school.associated_audits
school.subjects.each { |subject| audits += subject.associated_audits }
,School
和Subject
的整个审核集合。这是你追求的那种吗?
答案 1 :(得分:0)
经过审核的gem现在具有一个辅助方法:
您可以一次访问记录自己的审核和相关的审核:
company.own_and_associated_audits