method
count_by_sql
v3.0.9 -
Show latest stable
-
1 note -
Class: ActiveRecord::Base
- 1.0.0 (0)
- 1.1.6 (0)
- 1.2.6 (0)
- 2.0.3 (24)
- 2.1.0 (1)
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0 (0)
- 3.0.9 (-1)
- 3.1.0 (0)
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
count_by_sql(sql)
public
Returns the result of an SQL statement that should only include a COUNT(*) in the SELECT part. The use of this method should be restricted to complicated SQL queries that can’t be executed using the ActiveRecord::Calculations class methods. Look into those before using this.
Parameters
-
sql - An SQL statement which should return a count query from the database, see the example below.
Examples
Product.count_by_sql "SELECT COUNT(*) FROM sales s, customers c WHERE s.customer_id = c.id"
Register or
log in
to add new notes.
szeryf -
February 17, 2009
0 thanks
If you want to avoid SQL...
…you’re probably looking for http://apidock.com/rails/ActiveRecord/Calculations/ClassMethods/count