在此主题中知道how to make a eager load in rails,但如何执行此嵌套?
即:
# get category, random product and random photo
@category = Category.find(params[:id], :include => random_product, :include => random_photo)
我不知道我是否解释......
提前致谢。
答案 0 :(得分:4)
您可以通过向:include选项提供哈希来急切加载嵌套关联:
@category = Category.find(params[:id], :include => { :random_product => :random_photo})