[英]Implementation of multiple active record associations
I'm trying to set up models for my Ruby on Rails app and the models are quite complicated -- I'm not sure if I'm approaching it in the right way. 我正在尝试为我的Ruby on Rails应用设置模型,这些模型非常复杂-我不确定我是否以正确的方式进行处理。 Reading up on the Ruby on Rails guides @ guides.rubyonrails.org gives some pretty good information about Active Record associations but it also confused me a good deal more to an extent.
阅读Ruby on Rails指南@ guides.rubyonrails.org可以得到有关Active Record关联的一些很好的信息,但是在一定程度上也使我感到困惑。 What I'm trying to set up is something that models a tournament but not a traditional tournament (if anyone follows the GSL, that's the tournament I'd like to try to model).
我要建立的模型是对锦标赛进行建模的,而不是传统的锦标赛(如果有人遵循GSL,那就是我想建模的锦标赛)。
The tournament model stores the following information: 锦标赛模型存储以下信息:
These are the models I have come up with: Tournament, Map Pool, Map, Player, Race (ie Protoss Terran or Zerg), Team (ie what team the player belongs to), Round_of_32, Round_of_16, Round_of_8, Round_of_4, Round_of_2, Group (a collection of matches per round), Match (a collection that has information per matchup between players), and a Game (which holds a map and a winner). 这些是我想出的模型:锦标赛,地图池,地图,玩家,种族(即Protoss Terran或Zerg),团队(即玩家所属的团队),Round_of_32,Round_of_16,Round_of_8,Round_of_4,Round_of_2,组(每轮比赛的集合),比赛(每个球员之间的每个比赛都有信息的集合)和游戏(包含地图和获胜者)。 As the app develops, I will be having more and more tournaments, each with its own set of data, even though players could be parts of multiple tournaments and maps could be part of multiple map pools for their respective tournaments, etc.
随着应用程序的发展,我将拥有越来越多的比赛,每个比赛都有自己的数据集,即使玩家可能是多个比赛的一部分,而地图也可能是各自比赛的多个地图池的一部分,等等。
Here is what I have so far: 这是我到目前为止有:
TOURNAMENT
:league
:banner
has_one :map_pool
has_many :maps, :through => :map_pool
has_and_belongs_to_many :players
# has_many :rounds
has_one :ro32
has_one :ro16
has_one :ro8
has_one :ro4
has_one :ro2
MAP_POOL
belongs_to :tournament
has_many :maps
MAP
:name
belongs_to :map_pool
has_many :games
PLAYER
:name
belongs_to :race
belongs_to :team
has_and_belongs_to_many :tournaments
has_many :games
RACE
:type {"Protoss", "Terran", "Zerg"}
has_many :players
TEAM
:name
has_many :players
RO32
belongs_to :tournament
has_many :groups, :as => :round,
:limit => 8
RO16
belongs_to :tournament
has_many :groups, :as => :round,
:limit => 4
RO8
belongs_to :tournament
has_many :matches, :as => :matchup,
:limit => 4
RO4
belongs_to :tournament
has_many :matches, :as => :matchup,
:limit => 2
RO2
belongs_to :tournament
has_many :matches, :as => :matchup,
:limit => 1
GROUP
:name
belongs_to :round, :polymorphic => true
has_many :matchups, :as => :matchup
MATCH
:type {"bo3", "bo5", "bo7"}
has_many :games
belongs_to :matchup, :polymorphic => true
GAME
belongs_to :match
has_one :map
has_one :player
Am I missing anything or using anything incorrectly? 我是否缺少任何东西或使用不正确的东西?
EDIT: The reason why I have separate models for each individual round is because of the way Rounds 32/16 are different from Rounds 8/4/2. 编辑:为什么我每个回合都有单独的模型是因为回合32/16与回合8/4/2的方式不同。 Here is a set of sample data that may explain the issues I'm having:
这是一组示例数据,可以解释我遇到的问题:
Round of 32:
Group A:
Match 1: P1 vs P2
Game 1
Game 2
Game 3
Match 2: P3 vs P4
Game 1
Game 2
Game 3
Winners Match: P1 (winner match 1) vs P4 (winner match 2)
Game 1
Game 2
Game 3
Losers Match: P2 (loser match 1) vs P3 (loser match 2)
Game 1
Game 2
Game 3
Tiebreak Match: P4 (loser of winners match) vs P2 (winner of losers match)
Game 1
Game 2
Game 3
[etc. Group B through Group H]
Round of 16:
[similar to Round of 32 but only groups A through D]
Round of 8:
Match 1: P1 vs P2
Game 1
Game 2
Game 3
Game 4
Game 5
Match 2: P3 vs P4
Game 1
Game 2
Game 3
Game 4
Game 5
Match 3: P5 vs P6
Game 1
Game 2
Game 3
Game 4
Game 5
Match 4: P7 vs P8
Game 1
Game 2
Game 3
Game 4
Game 5
I'd still say your rounds should be a single model. 我仍然会说你的回合应该是一个单一的模型。 It seems that the differences between they types are logical not structural.
它们之间的差异似乎是逻辑上的而不是结构上的。 So I'd do a Round table and add the type attribute (take advantage of single table inheritance ?).
因此,我将做一个圆桌会议并添加type属性(利用单表继承?)。
As a fellow SC fan I'd be happy to help model it out if you like. 作为资深SC粉丝,如果您愿意,我很乐意为您建模。
Also: player >-- race ? 另外:球员>-种族? Are you sure?
你确定吗? I can't change races between games or even tournaments?!
我不能在游戏之间甚至比赛之间改变种族吗?!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.