seems like i found how to do it for one user
File.where(:users => {:id => 1}).count(:all, :include => {:tasks
=> :user})
but how to get hash with 'user' -> 'files count' using one query,
or may be even use something like counter cache.
On Wed, 2011-01-26 at 20:14 +0100, Robert Walker wrote:
> sl_bug wrote in post #977638:
> > I want to know files count for some user. is there some 'right' way to
> > do it without getting all tasks and looping it?
> >
> > P.S. there is really many tasks and files.
>
> ActiveRecord includes aggregate calculations for this purpose that
> perform the counts, sums, averages, etc. at the SQL layer:
>
> http://railsapi.com/doc/rails-v3.0.3/classes/ActiveRecord/Calculations.html
>
> --
> Posted via http://www.ruby-forum.com/.
>
--
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.