私は競馬アプリケーションに取り組んでおり、STI を利用して馬のつながりをモデル化しようとしています。馬のコネクションは、所有者、調教師、騎手で構成されています。時間の経過とともに、接続はさまざまな理由で変化する可能性があります。
- 馬は別の所有者に売却されます
- オーナーが調教師や騎手を交代
- 馬は新しい所有者によって主張されています
現在のところ、次の表でこれをモデル化しています。
- 馬
- 接続 (結合テーブル)
- 利害関係者 (利害関係者には、ジョッキー、トレーナー、所有者の 3 つのサブクラスがあります)
ここに私のクラスと協会があります:
class Horse < ActiveRecord::Base
has_one :connection
has_one :owner_stakeholder, :through => :connection
has_one :jockey_stakeholder, :through => :connection
has_one :trainer_stakeholder, :through => :connection
end
class Connection < ActiveRecord::Base
belongs_to :horse
belongs_to :owner_stakeholder
belongs_to :jockey_stakeholder
belongs_to :trainer_stakeholder
end
class Stakeholder < ActiveRecord::Base
has_many :connections
has_many :horses, :through => :connections
end
class Owner < Stakeholder
# Owner specific code goes here.
end
class Jockey < Stakeholder
# Jockey specific code goes here.
end
class Trainer < Stakeholder
# Trainer specific code goes here.
end
データベース側で、接続テーブルに Type 列を挿入しました。
これを正しくモデル化しましたか。より良い/よりエレガントなアプローチはありますか? フィードバックをお寄せいただきありがとうございます。
ジム