所有的例子:加載的加載都是用於類級別的查詢。我在我的模型實例上試過了,它仍然發佈了一堆查詢 - 它是否適用於實例方法?是否:包含ActiveRecord實例上的工作?
#in controller
@emails = person.sent_emails(:include => [:recipient])
#in view
render @emails
# _email.html.erb partial
<h1><%= email.recipient.name %></h1>
<p>
<%= email.content %>
</p>
#still issues a select * for emails, N+1 for recipients :/
什麼是局部'_email'裏面? – 2011-05-08 20:52:02
將其添加到問題 – 2011-05-08 20:54:50
如果收件人不是急於加載,那麼'email.recipient'調用應該運行'select * from users'。你確定你看到多次從電子郵件中選擇*嗎? – 2011-05-08 20:58:22