タイトルはあまり説明的ではありませんが、基本的には Game モデルがあり、各ゲームには _many Stats があります。これらの統計は、多くのゲームを持っているアスリートにも属します。各 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>]