Ruby on rails 在to_xml中包含子类

Ruby on rails 在to_xml中包含子类,ruby-on-rails,xml,inheritance,sti,Ruby On Rails,Xml,Inheritance,Sti,以下问题: 我正在生成数据库模型的xml文档。通过STI进行遗传 我的模型: class Entity < ActiveRecord::Base has_many :properties belongs_to :relationship end class Property < ActiveRecord::Base include Extensions::UUID belongs_to :entity, :foreign_key => 'pro

以下问题: 我正在生成数据库模型的xml文档。通过STI进行遗传

我的模型:

class Entity < ActiveRecord::Base
    has_many :properties
    belongs_to :relationship
end

class Property < ActiveRecord::Base
    include Extensions::UUID
    belongs_to :entity, :foreign_key => 'property_uid'

  #just there for xml-creation
    has_one :enum, :foreign_key => 'attribute_uid'
    has_many :entities, :foreign_key => 'relationship_uid'
end

class Attribute < Property
    has_one :enum, :foreign_key => 'attribute_uid'
end

class Relationship < Property
has_many :entities, :foreign_key => 'relationship_uid'
end
这目前是可行的,但似乎只是一种变通方法,因为属性必须与从属性继承的类具有相同的关系

我要寻找的是一个算法,它可以查看当前属性是属性还是关系,以及包含相应关系的属性

  def self.xml_includes
    includes = {}
    includes[:properties] = { :include => :enum, :include => :entities } 
    return includes
  end