Rails eager loading
HI, I have a Test model, which has_many questions, and Question, which has_many answers... When I make a query for a Test with :include => [:questions, {:questions => :answers}] ActiveRecord makes two more queries to fetch the questions and then to fetch the answers - it doesn`t join them!!! When I do the query with :joins ActiveRecord makes the query, but later when I need the Test.questions or Test.questions.answers ActiveRecord makes again those开发者_Go百科 2 extra queries!!! And later when I enumerate the questions or answers in the log I see other queries for each object, but it has Cache tag...
Is this normal?
I agree with shteef, what happens when you do the following:
:include => { :questions => :answers }
精彩评论