0

标题不太解释,但基本上我有一个游戏模型,每个游戏都有_many Stats。这些统计数据也属于_拥有_many Games的运动员。每个 Stat 都有一个 Stat_Type,我正在以下代码中收集我需要的 StatType:

@games = Athlete.first.games
unless @games.blank?
    @sport_position_stat_types = @games.first.stats.not_calculated.order("id ASC").collect(&:stat_type)
end

这很好用,但是我需要一种方法来删除此列表中的任何 stat_type ,其中在任何具有价值的游戏中都没有该 stat_type 的统计信息。

基本上,我现在拥有我需要的所有 stat_types,但我需要将 @sport_position_stat_types 限制为仅 stat_types 具有该运动员游戏集合中的值的统计数据。

所以这就是我需要的:

Athlete
-->Games
  -->Stats
    -->Stat_Types (I need all of these as long as there is at least ONE stat of that stat_type that is in the above Athlete's Games, and doesn't have a nil Value column--aka it has a value)

我希望这能很好地解释它。任何帮助表示赞赏!

编辑::

这是返回的内容(@sport_position_stat_types):

[#<StatType id: 270, sport_id: 6, name: "Return Touchdowns", unit: "", created_at: 
"2012-12-31 19:20:37", updated_at: "2013-04-29 15:19:59", lower_is_better: false, 
sport_position_id: 5, display_as_decimal: false, game: true, placement: 28, 
stat_type_category_id: 1, abbreviation: nil, calculated: false>, 
#<StatType id: 269, sport_id: 6, name: "Receiving Touchdowns", unit: "", created_at: "2012-
12-31 19:20:10", updated_at: "2013-04-29 15:19:59", lower_is_better: false, 
sport_position_id: 5, display_as_decimal: false, game: true, placement: 29, 
stat_type_category_id: 1, abbreviation: nil, calculated: false>, #<StatType id: 268, 
sport_id: 6, name: "Yards Per Catch", unit: "", created_at: "2012-12-31 19:18:33", 
updated_at: "2013-04-29 15:19:59", lower_is_better: false, sport_position_id: 5, 
display_as_decimal: true, game: true, placement: 30, stat_type_category_id: 1, abbreviation: nil, calculated: false>,
 #<StatType id: 267, sport_id: 6, name: "Receiving Yards", unit: "", created_at: "2012-12-31
 19:18:00", updated_at: "2013-04-29 15:19:59", lower_is_better: false, sport_position_id: 5,
 display_as_decimal: false, game: true, placement: 31, stat_type_category_id: 1, 
abbreviation: nil, calculated: false>, #<StatType id: 266, sport_id: 6, name: "Catches", 
unit: "", created_at: "2012-12-31 19:16:24", updated_at: "2013-04-29 15:19:59", 
lower_is_better: false, sport_position_id: 5, display_as_decimal: false, game: true, 
placement: 32, stat_type_category_id: 1, abbreviation: nil, calculated: false>, 
#<StatType id: 265, sport_id: 6, name: "Fumbles", unit: "", created_at: "2012-12-31 
19:09:41", updated_at: "2013-04-29 15:19:59", lower_is_better: true, sport_position_id: 5, 
display_as_decimal: false, game: true, placement: 33, stat_type_category_id: 1, 
abbreviation: nil, calculated: false>, 
#<StatType id: 264, sport_id: 6, name: "Rushing Touchdowns", unit: "", created_at: "2012-12-
31 19:09:10", updated_at: "2013-08-20 15:48:48", lower_is_better: false, sport_position_id:
 5, display_as_decimal: false, game: true, placement: 34, stat_type_category_id: 4, 
abbreviation: nil, calculated: false>, 
#<StatType id: 263, sport_id: 6, name: "Rush Long", unit: "", created_at: "2012-12-31
 19:08:42", updated_at: "2013-08-20 15:48:48", lower_is_better: false, sport_position_id: 5,
 display_as_decimal: false, game: true, placement: 35, stat_type_category_id: 4, 
abbreviation: nil, calculated: false>, 
#<StatType id: 262, sport_id: 6, name: "Rush Yards per Carry", unit: "yard", created_at: 
"2012-12-31 19:06:49", updated_at: "2013-08-20 15:48:48", lower_is_better: false, 
sport_position_id: 5, display_as_decimal: true, game: true, placement: 36, 
stat_type_category_id: 4, abbreviation: nil, calculated: false>, 
#<StatType id: 261, sport_id: 6, name: "Rush Yards", unit: "yard", created_at: "2012-12-31
 19:06:01", updated_at: "2013-08-20 15:48:47", lower_is_better: false, sport_position_id: 5,
 display_as_decimal: false, game: true, placement: 37, stat_type_category_id: 4, 
abbreviation: nil, calculated: false>, 
#<StatType id: 260, sport_id: 6, name: "Rushes", unit: "", created_at: "2012-12-31
 19:05:24", updated_at: "2013-08-20 15:48:48", lower_is_better: false, sport_position_id: 5,
 display_as_decimal: false, game: true, placement: 38, stat_type_category_id: 4, 
abbreviation: nil, calculated: false>]
4

1 回答 1

0

尝试这个:

@games = Athlete.first.games
unless @games.blank?
    @sport_position_stat_types = @games.first.stats.not_calculated.order("id ASC").collect(&:stat_type)
    @sport_position_stat_types.reject(&:blank?)
end
于 2013-10-03T18:40:08.287 回答