Rails eager loading
Posted
by Dimitar Vouldjeff
on Stack Overflow
See other posts from Stack Overflow
or by Dimitar Vouldjeff
Published on 2010-05-24T10:25:39Z
Indexed on
2010/05/24
10:31 UTC
Read the original article
Hit count: 418
ruby-on-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 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?
© Stack Overflow or respective owner