I'm having an N+1 query issue with the following active record query...
@interviews.each do |interview|
I want to solve it by adding :college_play_histories
to the active record query through using .includes(:college_play_histories)
, but currently that association doesn't exist between interviews and college_play_histories. I was going to setup an association between Interview
and CollegePlayHistory
, but this seemed incorrect to me and I wasn't sure if there was a way to specify the college_play_histories
in the includes through player
.
to
@interviews.includes(:college_play_history).each do |interview|
Here are my current models and associations:
Interview
class Interview < ActiveRecord::Base
belongs_to :player
end
Player
class Player < ActiveRecord::Base
has_many :interviews
has_many :college_play_histories
end
CollegePlayHistory
class CollegePlayHistory < ActiveRecord::Base
belongs_to :player
end