Forum: Ruby on Rails Returning a "select count()" in ActiveRecord

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Fbfee2c29edaacecc28f616aa0b542f4?d=identicon&s=25 kevin (Guest)
on 2006-02-24 02:36
I am trying to find the count of rows on a table.  If I do a
         result=  Table.find_by_sql ("select count(distinct id) ......

It returns an array of Table with Hashes of "select count(distinct id)"
making accessing it a pain
              result[0]['select count(distinct id)']

It seems easier to return all the rows and do a .length on the result

What is the proper way to do this ?

27c57aaa4bda5ac8b0593659573b522f?d=identicon&s=25 Blair Zajac (Guest)
on 2006-02-24 03:07
(Received via mailing list)
kevin wrote:
> What is the proper way to do this ?
There is a Table.count_by_sql class method that you can use.


Blair Zajac, Ph.D.
Subversion training, consulting and support
This topic is locked and can not be replied to.