2017-02-12 259 views
0

我有4个型号,每个定义如下创建多个模型 - 一类的Rails

--Model/Table-- 
Competition 
Matches 
Goals 
Teams 

这4款车型完成了一个赛季的身价足球联赛的数据。这些表之间的关系已经定义。现在,我想创建一个类,它从所有4个模型中提取数据并生成1个新类。像这样:

class CompetitionSeason < ApplicationRecord 
    # Use data from all 4 models to construct a soccer season class 
end 

这是我的意图,但我不确定这是否是这样做的最佳做法。感觉......在Rails框架级别上是错误的。达到此目的的最佳做法是什么?

谢谢。

+0

加入到一起意味着什么,这可能意味着很多东西? – Iceman

+0

我认为“使用4个模型构建班级”是一个更好的方式来表达它。例如: CompetitionSeason.Matches =包含团队(模型)和目标(模型)数据的匹配模型数组 – jaimeT

+0

这非常像是数据库视图的工作。 – Iceman

回答

0

您应该真的有另一个模型Season或某些拥有(has_(one|many))每个组成部分。我不确定Competition是什么。

Match可以属于Competition或直接到Season。我不明白Competition是什么,所以我不能提出一个好的建议。

Goal应该属于MatchCompetition,而不是直接给SeasonSeason仍然可以通过MatchCompetition有很多目标。

Team应该有一个SeasonTeam联结表。