Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added a join parameter as the third argument to Base.find_first and a…

…s 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
  • Loading branch information...
commit 06a6133fff7ddac177dde63c3303e1209c9e5518 1 parent 0ca544d
@dhh dhh authored
View
2  activerecord/CHANGELOG
@@ -1,6 +1,6 @@
*SVN*
-* Added a join parameter as the third argument to Base.find_first #426 [skaes@web.de]
+* Added a join parameter as the third argument to Base.find_first and as the second to Base.count #426, #988 [skaes@web.de]
* Fixed bug in Base#hash method that would treat records with the same string-based id as different [Dave Thomas]
View
6 activerecord/lib/active_record/base.rb
@@ -452,8 +452,10 @@ def delete_all(conditions = nil)
# 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
Please sign in to comment.
Something went wrong with that request. Please try again.