【发布时间】:2011-03-17 11:42:04
【问题描述】:
我正在构建一个 Rails 应用程序,允许运动员创建和管理骨骼运动的时间表。我似乎无法将我的大脑包裹在我的模型之间的正确关联上。这是我到目前为止所拥有的。 运动员有Runs,由几个Splits组成。每个单独的分段都应与雪橇/骨架赛道上的特定计时Eye相关联。在特定日期、特定赛道和特定Circuit上运行的集合被组织成时间表。运动员创建时间表,将跑步和分段添加到时间表,然后能够在时间表上查看跑步并绘制图表。唷。这是一些代码:
class Athlete < ActiveRecord::Base
has_many :runs
has_many :timesheets, :through => :runs
end
class Run < ActiveRecord::Base
belongs_to :athlete
belongs_to :timesheet
has_many :splits
end
class Timesheet < ActiveRecord::Base
has_many :runs
has_many :athletes, :through => :runs
belongs_to :track
belongs_to :circuit
end
class Split < ActiveRecord::Base
belongs_to :run
belongs_to :eye
end
class Track < ActiveRecord::Base
has_many :timesheets
has_many :eyes
end
class Circuit < ActiveRecord::Base
has_many :timesheets
end
class Eye < ActiveRecord::Base
has_many :runs
has_many :splits
belongs_to :track
end
我好像在这里做了一些不必要的联想。我最大的挫败感是将拆分与时间表视图表中的计时眼和轨道相关联。表格标题是当天打开的计时眼(并非每天都打开每个计时眼),而表格单元格是实际的分段时间(有时,计时眼会错过运动员在跑步期间的特定分段)。
您认为这些关联有哪些可以改进的地方吗?
【问题讨论】:
-
时间表是涵盖多位运动员的跑步,还是仅涵盖一名运动员的跑步?
-
它涵盖了多个运动员的跑步。运动员也可以在一个时间表上进行多次跑步......
标签: ruby-on-rails database-design associations