如何解决我在Rails中使用活动记录查询获得的N + 1查询?

时间:2015-06-02 17:07:11

标签: mysql ruby-on-rails activerecord associations

我遇到了以下有效记录查询的N + 1查询问题......

@interviews.each do |interview|

我想通过使用:college_play_histories.includes(:college_play_histories)添加到活动记录查询来解决此问题,但目前在访谈和college_play_histories之间不存在该关联。我打算在InterviewCollegePlayHistory之间设置关联,但这对我来说似乎不正确,我不确定是否有办法在include中指定college_play_histories { {1}}。

player

以下是我目前的模特和协会:

访

@interviews.includes(:college_play_history).each do |interview|

播放器

class Interview < ActiveRecord::Base
  belongs_to :player
end

CollegePlayHistory

class Player < ActiveRecord::Base
  has_many :interviews
  has_many :college_play_histories
end

0 个答案:

没有答案