Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails—为什么在这种情况下不使用即时加载?_Ruby On Rails_Eager - Fatal编程技术网

Ruby on rails Rails—为什么在这种情况下不使用即时加载?

Ruby on rails Rails—为什么在这种情况下不使用即时加载?,ruby-on-rails,eager,Ruby On Rails,Eager,我有这3种型号,它们之间有着千丝万缕的联系: class Wine < ActiveRecord::Base has_many :varietals, :conditions => "varietals.status = 1" has_many :grapes, :through => :varietals end class Grape < ActiveRecord::Base has_many :varietals has_many :wines,

我有这3种型号,它们之间有着千丝万缕的联系:

class Wine < ActiveRecord::Base
  has_many :varietals, :conditions => "varietals.status = 1"
  has_many :grapes, :through => :varietals
end

class Grape < ActiveRecord::Base
  has_many :varietals
  has_many :wines, :through => :varietals
end

class Varietal < ActiveRecord::Base
  belongs_to :wine
  belongs_to :grape
end

@records = Wine.where(conditions).includes({:varietals => :grape})
如何在主请求中加载grapes以使每个grapes都没有请求?

尝试以下方法:

Wine.includes(:varietals).includes(:grapes).where(conditions)
如果有效,不要问我为什么;)

Wine.includes(:varietals).includes(:grapes).where(conditions)