Ruby on Rails Thursday, April 29, 2010

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/Calculations/ClassMethods.html#M001357
>
> 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-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment