标题不是太多解释,但基本上我有一个游戏模型,每个游戏的has_many统计。这些统计数据也是一个运动员,谁has_many游戏。每个Stat都有一个Stat_Type,我在下面的代码中收集所需的StatTypes:
@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>]发布于 2013-10-04 02:40:08
试试这个:
@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?)
endhttps://stackoverflow.com/questions/19146937
复制相似问题