aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2007-07-16 20:26:10 +0000
committerRick Olson <technoweenie@gmail.com>2007-07-16 20:26:10 +0000
commit872c5f4380ca348ff9ed19963e827289fb831fdf (patch)
tree47f486fb23a24dfaba9b16cf6c87d16d751c8f52 /activerecord
parent4ef5af8d4ddad82295920cc7d83fba6cbb10ad71 (diff)
downloadrails-872c5f4380ca348ff9ed19963e827289fb831fdf.tar.gz
rails-872c5f4380ca348ff9ed19963e827289fb831fdf.tar.bz2
rails-872c5f4380ca348ff9ed19963e827289fb831fdf.zip
Remove deprecated count(conditions=nil, joins=nil) usage. Closes #8993 [lifofifo]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7189 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/associations/has_many_association.rb2
-rw-r--r--activerecord/lib/active_record/calculations.rb37
-rwxr-xr-xactiverecord/test/associations_test.rb4
-rwxr-xr-xactiverecord/test/base_test.rb7
-rw-r--r--activerecord/test/calculations_test.rb4
6 files changed, 16 insertions, 40 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 4c0625b8db..3d6413a427 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Remove deprecated count(conditions=nil, joins=nil) usage. Closes #8993 [lifofifo]
+
* Change belongs_to so that the foreign_key assumption is taken from the association name, not the class name. Closes #8992 [hasmanyjosh]
OLD
diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb
index 1c96353863..393d59b084 100644
--- a/activerecord/lib/active_record/associations/has_many_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_association.rb
@@ -27,7 +27,7 @@ module ActiveRecord
elsif @reflection.options[:finder_sql]
@reflection.klass.count_by_sql(@finder_sql)
else
- column_name, options = @reflection.klass.send(:construct_count_options_from_legacy_args, *args)
+ column_name, options = @reflection.klass.send(:construct_count_options_from_args, *args)
options[:conditions] = options[:conditions].nil? ?
@finder_sql :
@finder_sql + " AND (#{sanitize_sql(options[:conditions])})"
diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb
index ef59db915a..0a71c92c01 100644
--- a/activerecord/lib/active_record/calculations.rb
+++ b/activerecord/lib/active_record/calculations.rb
@@ -6,13 +6,12 @@ module ActiveRecord
end
module ClassMethods
- # Count operates using three different approaches.
+ # Count operates using two different approaches.
#
# * Count all: By not passing any parameters to count, it will return a count of all the rows for the model.
- # * Count by conditions or joins: This API has been deprecated and will be removed in Rails 2.0
# * Count using options will find the row count matched by the options used.
#
- # The last approach, count using options, accepts an option hash as the only parameter. The options are:
+ # The second approach, count using options, accepts an option hash as the only parameter. The options are:
#
# * <tt>:conditions</tt>: An SQL fragment like "administrator = 1" or [ "user_name = ?", username ]. See conditions in the intro.
# * <tt>:joins</tt>: An SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = id". (Rarely needed).
@@ -29,10 +28,6 @@ module ActiveRecord
# Examples for counting all:
# Person.count # returns the total count of all people
#
- # Examples for count by +conditions+ and +joins+ (this has been deprecated):
- # Person.count("age > 26") # returns the number of people older than 26
- # Person.find("age > 26 AND job.salary > 60000", "LEFT JOIN jobs on jobs.person_id = person.id") # returns the total number of rows matching the conditions and joins fetched by SELECT COUNT(*).
- #
# Examples for count with options:
# Person.count(:conditions => "age > 26")
# Person.count(:conditions => "age > 26 AND job.salary > 60000", :include => :job) # because of the named association, it finds the DISTINCT count using LEFT OUTER JOIN.
@@ -42,7 +37,7 @@ module ActiveRecord
#
# Note: Person.count(:all) will not work because it will use :all as the condition. Use Person.count instead.
def count(*args)
- calculate(:count, *construct_count_options_from_legacy_args(*args))
+ calculate(:count, *construct_count_options_from_args(*args))
end
# Calculates average value on a given column. The value is returned as a float. See #calculate for examples with options.
@@ -125,7 +120,7 @@ module ActiveRecord
end
protected
- def construct_count_options_from_legacy_args(*args)
+ def construct_count_options_from_args(*args)
options = {}
column_name = :all
@@ -133,25 +128,13 @@ module ActiveRecord
# count()
# count(options={})
# count(column_name=:all, options={})
- # count(conditions=nil, joins=nil) # deprecated
- if args.size > 2
+ if args[0].is_a?(Hash)
+ options = args[0]
+ elsif args[1].is_a?(Hash)
+ column_name, options = args
+ else
raise ArgumentError, "Unexpected parameters passed to count(options={}): #{args.inspect}"
- elsif args.size > 0
- if args[0].is_a?(Hash)
- options = args[0]
- elsif args[1].is_a?(Hash)
- column_name, options = args
- else
- # Deprecated count(conditions, joins=nil)
- ActiveSupport::Deprecation.warn(
- "You called count(#{args[0].inspect}, #{args[1].inspect}), which is a deprecated API call. " +
- "Instead you should use count(column_name, options). Passing the conditions and joins as " +
- "string parameters will be removed in Rails 2.0.", caller(2)
- )
- options.merge!(:conditions => args[0])
- options.merge!(:joins => args[1]) if args[1]
- end
- end
+ end if args.size > 0
[column_name, options]
end
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index 0db8d91099..607f12bdb5 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -433,9 +433,7 @@ class HasManyAssociationsTest < Test::Unit::TestCase
end
def test_counting_with_single_conditions
- assert_deprecated 'count' do
- assert_equal 2, Firm.find(:first).plain_clients.count('1=1')
- end
+ assert_equal 2, Firm.find(:first).plain_clients.count(:conditions => '1=1')
end
def test_counting_with_single_hash
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index 5a224bfbb8..2851665345 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -1330,11 +1330,8 @@ class BasicsTest < Test::Unit::TestCase
def test_count_with_join
res = Post.count_by_sql "SELECT COUNT(*) FROM posts LEFT JOIN comments ON posts.id=comments.post_id WHERE posts.#{QUOTED_TYPE} = 'Post'"
- res2 = nil
- assert_deprecated 'count' do
- res2 = Post.count("posts.#{QUOTED_TYPE} = 'Post'",
- "LEFT JOIN comments ON posts.id=comments.post_id")
- end
+
+ res2 = Post.count(:conditions => "posts.#{QUOTED_TYPE} = 'Post'", :joins => "LEFT JOIN comments ON posts.id=comments.post_id")
assert_equal res, res2
res3 = nil
diff --git a/activerecord/test/calculations_test.rb b/activerecord/test/calculations_test.rb
index bf34beb702..faa86c43f2 100644
--- a/activerecord/test/calculations_test.rb
+++ b/activerecord/test/calculations_test.rb
@@ -233,10 +233,6 @@ class CalculationsTest < Test::Unit::TestCase
assert_equal 4, Account.count(:distinct => true, :include => :firm, :select => :credit_limit)
end
- def test_deprecated_count_with_string_parameters
- assert_deprecated('count') { Account.count('credit_limit > 50') }
- end
-
def test_count_with_no_parameters_isnt_deprecated
assert_not_deprecated { Account.count }
end