method

count_by_sql

Importance_2
Ruby on Rails latest stable (v7.1.3.2) - 1 note - Class: ActiveRecord::Base

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v3.1.0) is shown here.

These similar methods exist in v7.1.3.2:

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"
Show source
Register or log in to add new notes.