我无法为子表记录关联审核检索auditable_type
,因为它始终提供父表类名。
我有:
class Patient < ActiveRecord::Base
has_many :diseases
has_associated_audits
end
class Disease < MedicalHistory
belongs_to :patient
audited associated_with :patient
end
class MedicalHistory < ActiveRecord::Base
end
当我让Patient.last.associated_audits.last.auditable_type
给予MedicalHistory而不是疾病时。
请尽快通知我。
答案 0 :(得分:1)
是的,这个宝石一直是个问题。
但您可以先检索审核记录,然后识别其类名称,如:
Patient.last.associated_audits.last.auditable.class.name
实际上,在单表继承(STI)中,每个记录都有一个唯一的ID,因此您可以使用父类中的记录ID来标识记录MedicalHistory.find(child_id)