Permalink
Browse files

Add documentation caveat about when to use count_by_sql. Closes #8090.…

… [fearoffish]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6685 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 15dc567 commit ee614d6319d3704a2f92e262a0270812761a8e4e Marcel Molina committed May 6, 2007
Showing with 11 additions and 0 deletions.
  1. +2 −0 activerecord/CHANGELOG
  2. +9 −0 activerecord/lib/active_record/base.rb
View
@@ -1,5 +1,7 @@
*SVN*
+* Add documentation caveat about when to use count_by_sql. [fearoffish]
+
* Enhance documentation for increment_counter and decrement_counter. [fearoffish]
* Provide brief introduction to what optimistic locking is. [fearoffish]
@@ -530,6 +530,15 @@ def delete_all(conditions = nil)
end
# 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.
+ #
+ # ==== Options
+ #
+ # +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"
def count_by_sql(sql)
sql = sanitize_conditions(sql)

0 comments on commit ee614d6

Please sign in to comment.