Skip to content

Commit

Permalink
port [9018] to 2.0 stable
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/2-0-stable@9019 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
technoweenie committed Mar 13, 2008
1 parent 0e57097 commit b96db52
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Ensure that ActiveRecord::Calculations disambiguates field names with the table name. #11027 [cavalle]

* Ensure that modifying has_and_belongs_to_many actions clear the query cache. Closes #10840 [john.andrews]

* Fix issue where Table#references doesn't pass a :null option to a *_type attribute for polymorphic associations. Closes #10753 [railsjitsu]
Expand Down
1 change: 1 addition & 0 deletions activerecord/lib/active_record/calculations.rb
Expand Up @@ -155,6 +155,7 @@ def construct_calculation_sql(operation, column_name, options) #:nodoc:
scope = scope(:find)
merged_includes = merge_includes(scope ? scope[:include] : [], options[:include])
aggregate_alias = column_alias_for(operation, column_name)
column_name = "#{connection.quote_table_name(table_name)}.#{column_name}" unless column_name == "*" || column_name.to_s.include?('.')

if operation == 'count'
if merged_includes.any?
Expand Down
8 changes: 8 additions & 0 deletions activerecord/test/associations/join_model_test.rb
Expand Up @@ -536,6 +536,14 @@ def test_has_many_through_sum_uses_calculations
assert_nothing_raised { authors(:david).comments.sum(:post_id) }
end

def test_calculations_on_has_many_through_should_disambiguate_fields
assert_nothing_raised { authors(:david).categories.maximum(:id) }
end

def test_calculations_on_has_many_through_should_not_disambiguate_fields_unless_necessary
assert_nothing_raised { authors(:david).categories.maximum("categories.id") }
end

def test_has_many_through_has_many_with_sti
assert_equal [comments(:does_it_hurt)], authors(:david).special_post_comments
end
Expand Down

0 comments on commit b96db52

Please sign in to comment.