aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-09-24 19:50:57 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-09-24 19:50:57 +0000
commitcaaf40d5358ae8a2b31949c2af2d94be1be73976 (patch)
tree4a7d7cb629b8e730e0f2981fea60458eedcf9992 /activerecord/lib/active_record/base.rb
parent66820a4aa70889a02f48eb860727daa31639aab3 (diff)
downloadrails-caaf40d5358ae8a2b31949c2af2d94be1be73976.tar.gz
rails-caaf40d5358ae8a2b31949c2af2d94be1be73976.tar.bz2
rails-caaf40d5358ae8a2b31949c2af2d94be1be73976.zip
Added AbstractAdapter#select_value and AbstractAdapter#select_values as convenience methods for selecting single values, instead of hashes, of the first column in a SELECT #2283
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2323 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-xactiverecord/lib/active_record/base.rb8
1 files changed, 1 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 73c69a91d1..03123758ef 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -464,13 +464,7 @@ module ActiveRecord #:nodoc:
# 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)
- rows = connection.select_one(sql, "#{name} Count")
-
- if !rows.nil? and count = rows.values.first
- count.to_i
- else
- 0
- end
+ connection.select_value(sql, "#{name} Count").to_i
end
# Increments the specified counter by one. So <tt>DiscussionBoard.increment_counter("post_count",