1

次の問題: データベース モデルの 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

呼び出す XML を生成するにはEntity.to_xml(:skip_instruct => true, :include => Entity.xml_includes)

エンティティでは、self.includes次のようになります。

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

Propertyこれは現在機能していますが、は から継承するクラスと同じ関係を持たなければならないため、単なる回避策のようPropertyです。

私が探しているのは、現在のプロパティが anAttributeまたは aRelationshipであるかどうかを調べ、対応する関係を含めるアルゴリズムです。

4

0 に答える 0