2

次のテーブルを使用してデータベースを作成する必要があります:学校住所タイプ結果。各学校は1つの 住所多くの のみを持つことができ、各年には多くの タイプが必要であり、の各タイプには1つの結果テーブルしか持つことができません。

私のDataMapperモデルが拒否されています:

class School
  include DataMapper::Resource

  property :id, Serial
  property :title, String, :length => 225, :required => true
  property :type, String

  has n, :years
  has 1, :address
  has n, :types, :through => :years
  has n, :visits
end

class Year
  include DataMapper::Resource

  property :id, Serial
  property :year, Integer

  has n, :types
  has n, :schools

end

class Result
  include DataMapper::Resource

  property :id, Serial
  property :subject, String, :length => 225
  property :total, Integer
  property :range_1, Integer
  property :range_2, Integer
  property :range_3, Integer
  property :range_4, Integer
  property :range_5, Integer
  property :range_6, Integer
  property :range_7, Integer
  property :range_8, Integer
  property :range_9, Integer
  property :range_10, Integer

  belongs_to :type
end

class Type
  include DataMapper::Resource

  property :id, Serial
  property :name, String, :length => 225, :required => true

  has n, :results
  has n, :years
  has n, :schools, :through => :years
end

class Address
  include DataMapper::Resource

  property :id, Serial
  property :Village, String
  property :City, String
  property :District, String
  property :State, String

  belongs_to :school
end

テーブル間の関連付けを宣言するためのより良い方法を見つけることができません。たぶんあなたはもっと良いものを提案することができますか?

また、学校や学年に応じて具体的な結果を選択するにはどうすればよいですか?

4

0 に答える 0