1
私は関係を通じてhas_manyのでこれらの3つのモデルがあります:Rails - この場合、Eagerの読み込みが機能しないのはなぜですか?
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})
しかし、私は10本のワインを持っている場合、私はメインのワイン要求後に、これらのもののように私のログに10個の要求が表示されます。
Grape Load (0.6ms) SELECT `grapes`.* FROM `grapes` INNER JOIN `varietals` ON `grapes`.id = `varietals`.grape_id WHERE ((`varietals`.wine_id = '98DF2CEC-61CC-4B22-B40D-620AADF650D2') AND ((varietals.status = 1)))
メインリクエストでブドウをロードして、ブドウごとにリクエストしないようにするにはどうすればよいですか?
、これは動作しません。 –