Permalink
Browse files

Revert "Ensure calculations respect scoped :select". Broke .count on …

…a has_many :through association.

This reverts commit 6543426.
  • Loading branch information...
1 parent c73cf7d commit 34c3162c5c84a4393340e7fc5f7f7f37a828fc08 @NZKoz NZKoz committed Jun 1, 2009
Showing with 5 additions and 26 deletions.
  1. +5 −13 activerecord/lib/active_record/calculations.rb
  2. +0 −13 activerecord/test/cases/calculations_test.rb
@@ -141,30 +141,22 @@ def calculate(operation, column_name, options = {})
def construct_count_options_from_args(*args)
options = {}
column_name = :all
-
+
# We need to handle
# count()
# count(:column_name=:all)
# count(options={})
# count(column_name=:all, options={})
- # selects specified by scopes
case args.size
- when 0
- column_name = scope(:find)[:select] if scope(:find)
when 1
- if args[0].is_a?(Hash)
- column_name = scope(:find)[:select] if scope(:find)
- options = args[0]
- else
- column_name = args[0]
- end
+ args[0].is_a?(Hash) ? options = args[0] : column_name = args[0]
when 2
column_name, options = args
else
raise ArgumentError, "Unexpected parameters passed to count(): #{args.inspect}"
- end
-
- [column_name || :all, options]
+ end if args.size > 0
+
+ [column_name, options]
end
def construct_calculation_sql(operation, column_name, options) #:nodoc:
@@ -264,19 +264,6 @@ def test_should_count_selected_field_with_include
assert_equal 4, Account.count(:distinct => true, :include => :firm, :select => :credit_limit)
end
- def test_should_count_scoped_select
- Account.update_all("credit_limit = NULL")
- assert_equal 0, Account.scoped(:select => "credit_limit").count
- end
-
- def test_should_count_scoped_select_with_options
- Account.update_all("credit_limit = NULL")
- Account.last.update_attribute('credit_limit', 49)
- Account.first.update_attribute('credit_limit', 51)
-
- assert_equal 1, Account.scoped(:select => "credit_limit").count(:conditions => ['credit_limit >= 50'])
- end
-
def test_should_count_manual_select_with_include
assert_equal 6, Account.count(:select => "DISTINCT accounts.id", :include => :firm)
end

1 comment on commit 34c3162

thijsc commented on 34c3162 Jun 7, 2009

Thanks for this one :-)

Please sign in to comment.