I have the next three models:
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
Basically, A school
has many subjects
, and each subject
has many attachments
(the attachment
model is polymorphic because it's used for other models too, just in case it matters...)
The problem is that the audit is not working as I expect. I create a school, then a subject for that school, and then I add attachments to that subject. This is what I get from the console:
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
But I would need is School.last.associated_audits
to include attachments audited changes too.
Any ideas?
The audited gem now has a helper method: