我不清楚为什么在我的Rails应用程序中我的查询如此之大,例如我遇到这样的问题:
Recipe Load (4.0ms) SELECT `recipes`.* FROM `recipes` WHERE (recipes.id > 394691) ORDER BY recipes.id LIMIT 500
Ingredient Load (6.3ms) SELECT `ingredients`.* FROM `ingredients` WHERE (`ingredients`.recipe_id = 394692)
Step Load (1.7ms) SELECT `steps`.* FROM `steps` WHERE (`steps`.recipe_id = 394692)
Ingredient Load (0.6ms) SELECT `ingredients`.* FROM `ingredients` WHERE (`ingredients`.recipe_id = 394693)
Step Load (0.2ms) SELECT `steps`.* FROM `steps` WHERE (`steps`.recipe_id = 394693)
Ingredient Load (0.3ms) SELECT `ingredients`.* FROM `ingredients` WHERE (`ingredients`.recipe_id = 394694)
Step Load (0.2ms) SELECT `steps`.* FROM `steps` WHERE (`steps`.recipe_id = 394694)
Ingredient Load (0.4ms) SELECT `ingredients`.* FROM `ingredients` WHERE (`ingredients`.recipe_id = 394695)
Step Load (0.2ms) SELECT `steps`.* FROM `steps` WHERE (`steps`.recipe_id = 394695)
Ingredient Load (0.3ms) SELECT `ingredients`.* FROM `ingredients` WHERE (`ingredients`.recipe_id = 394696)
Step Load (0.2ms) SELECT `steps`.* FROM `steps` WHERE (`steps`.recipe_id = 394696)
Ingredient Load (0.3ms) SELECT `ingredients`.* FROM `ingredients` WHERE (`ingredients`.recipe_id = 394697)
Step Load (0.2ms) SELECT `steps`.* FROM `steps` WHERE (`steps`.recipe_id = 394697)
Ingredient Load (0.3ms) SELECT `ingredients`.* FROM `ingredients` WHERE (`ingredients`.recipe_id = 394698)
Step Load (0.2ms) SELECT `steps`.* FROM `steps` WHERE (`steps`.recipe_id = 394698)
Ingredient Load (0.3ms) SELECT `ingredients`.* FROM `ingredients` WHERE (`ingredients`.recipe_id = 394699)
[... goes on for like 20 more rows ...]
为什么会有这么多查询,我是否需要使用:include
或其他什么,我只是不知道该去哪里。
答案 0 :(得分:2)
是
看起来你可能想要
@recipe = Recipe.find(params[:id], :include => :ingredients))