Thanks guys, If I have nested associations, how could i count that? For ex-
I want to do something like @totalcount = Post.comment.count , or something like that How could i do that? ( i want to count the comments that belong to that post) thanks On Apr 29, 5:07 pm, Philip Hallstrom <phi...@pjkh.com> wrote: > On Apr 29, 2010, at 2:01 PM, Robert Walker wrote: > > > David Zhu wrote: > >> Is it possible to do a find all, and then return the # of items? > > > Better to use the built-in aggregate functions. > > >http://railsapi.com/doc/rails-v2.3.5/classes/ActiveRecord/Calculation... > > > This will perform the count in SQL and will be much more efficient > > than > > building all those ActiveRecord objects. > > +1, but if you already have them you can use .size() 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 rubyonrails-t...@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/rubyonrails-talk?hl=en. -- 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 rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.