aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Molina <marcel@vernix.org>2007-05-06 05:10:19 +0000
committerMarcel Molina <marcel@vernix.org>2007-05-06 05:10:19 +0000
commitee614d6319d3704a2f92e262a0270812761a8e4e (patch)
tree10c5c3a89e6dfc3381abeb1148d69827efc82019
parent15dc567e0fffb2b71d41185364ff5ffb505ec61f (diff)
downloadrails-ee614d6319d3704a2f92e262a0270812761a8e4e.tar.gz
rails-ee614d6319d3704a2f92e262a0270812761a8e4e.tar.bz2
rails-ee614d6319d3704a2f92e262a0270812761a8e4e.zip
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
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/base.rb9
2 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index d05261ae94..0c7e5c9fd2 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -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]
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 87bd064e49..bb3c58067d 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -530,6 +530,15 @@ module ActiveRecord #:nodoc:
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)