导轨中的SIT不适用于audited-activerecord

时间:2016-03-28 11:02:55

标签: ruby-on-rails ruby activerecord

我无法为子表记录关联审核检索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而不是疾病时。

请尽快通知我。

1 个答案:

答案 0 :(得分:1)

是的,这个宝石一直是个问题。

但您可以先检索审核记录,然后识别其类名称,如:

Patient.last.associated_audits.last.auditable.class.name

实际上,在单表继承(STI)中,每个记录都有一个唯一的ID,因此您可以使用父类中的记录ID来标识记录MedicalHistory.find(child_id)