Rails 急切加载
你好, 我有一个测试模型,其中有很多问题,还有一个问题,其中有很多答案...... 当我使用 :include => 查询测试时[:问题,{:问题=> :answers}] ActiveRecord 又进行了两个查询来获取问题,然后获取答案 - 它不会加入它们!当我使用 :joins ActiveRecord 进行查询时,ActiveRecord 会进行查询,但稍后当我需要 Test.questions 或 Test.questions.answers 时,ActiveRecord 会再次进行这两个额外的查询!后来,当我枚举日志中的问题或答案时,我看到每个对象的其他查询,但它有缓存标签......
这正常吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我同意 shteef 的观点,当您执行以下操作时会发生什么:
I agree with shteef, what happens when you do the following: