On Sep 16, 9:59 pm, "Franz Strebel" <[EMAIL PROTECTED]> wrote: > On Tue, Sep 16, 2008 at 3:55 PM, surge <[EMAIL PROTECTED]> wrote: > > > Sorry if this has been asked before... > > > I have a model named ticket (like a trouble ticket) and a ticket can > > have many issues. When I list tickets in a table I want to output the > > number of issues each ticket has. So, in my view I do something like: > > > <%= ticket.issues.count %> > > You should use eager loading to include the issues when you get the > tickets, à la > > @tickets = Ticket.find(:all, :include => :issues)
Depending upon your requirement, you could even optimize it further by using a view or include that gets the count directly via SQL, and thus avoid having to load all issues just to get the count. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

