I have four models
Group => has_many => Reports
Report => has_many => Comments
Comment => Belongs_to => User
When i want to show a group I do something like
<%= @group.name %>
<%= @group.reports.includes(:comments).each do |report| %>
<%= report.name %>
<% report.comments.each do |comment| %>
<%= comment.name %>
<%= comment.user.name %>
<% end %>
<% end %>
What is the best way to solve N+1 Query problems in this case ??
也许
@group.reports.includes(:comments => :user).each do |report|
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.