http://railscasts.com/episodes/23

On Feb 1, 2008, at 6:41 PM, tommy wrote:

>
> So this is really bugging me. I know you can eager include associated
> rows with the :include, but is there a way to include just the
> associated count?
>
> #how to eager include the store count?
> User.find(:all, :select => 'id, first_name, last_name,
> created_at', :limit => 30)
>
> Right now, this gives me n+1 queries because i get the count for each
> row.
>
> <% for user in @users %>
> <td><%= user.first_name + " " + user.last_name %></td>
> <%= user.stores.count %></td>
> <% end%>
>
>
> thanks,
> tommy
>
> >


--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---

Reply via email to