aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-04-02 08:29:54 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-04-02 08:29:54 +0000
commit06a6133fff7ddac177dde63c3303e1209c9e5518 (patch)
tree76207109c3da6f6c7caba6674832d0168a3c5c92 /activerecord/lib/active_record
parent0ca544d7b38c5f93b940c1709b361ba8d54d1194 (diff)
downloadrails-06a6133fff7ddac177dde63c3303e1209c9e5518.tar.gz
rails-06a6133fff7ddac177dde63c3303e1209c9e5518.tar.bz2
rails-06a6133fff7ddac177dde63c3303e1209c9e5518.zip
Added a join parameter as the third argument to Base.find_first and as the second to Base.count #426, #988 [skaes@web.de]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1058 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-xactiverecord/lib/active_record/base.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index bf36e9815b..d15b7e9986 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -452,8 +452,10 @@ module ActiveRecord #:nodoc:
# Returns the number of records that meets the +conditions+. Zero is returned if no records match. Example:
# Product.count "sales > 1"
- def count(conditions = nil)
- sql = "SELECT COUNT(*) FROM #{table_name} "
+ def count(conditions = nil, joins = nil)
+ tbl_var_name = joins ? table_name[0,1].downcase : ""
+ sql = "SELECT COUNT(*) FROM #{table_name} #{tbl_var_name} "
+ sql << ", #{joins} " if joins
add_conditions!(sql, conditions)
count_by_sql(sql)
end