method
count_by_sql
v1.0.0 -
Show latest stable
- Class:
ActiveRecord::Base
count_by_sql(sql)public
Returns the result of an SQL statement that should only include a COUNT(*) in the SELECT part.
Product.count_by_sql "SELECT COUNT(*) FROM sales s, customers c WHERE s.customer_id = c.id"
1Note
If you want to avoid SQL...
...you're probably looking for http://apidock.com/rails/ActiveRecord/Calculations/ClassMethods/count