diff options
-rw-r--r-- | activerecord/lib/active_record/calculations.rb | 4 | ||||
-rw-r--r-- | activerecord/test/reserved_word_test_mysql.rb | 5 |
2 files changed, 7 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb index 2327862f13..5ce31197d4 100644 --- a/activerecord/lib/active_record/calculations.rb +++ b/activerecord/lib/active_record/calculations.rb @@ -167,7 +167,7 @@ module ActiveRecord if operation == 'count' if merged_includes.any? options[:distinct] = true - column_name = options[:select] || [table_name, primary_key] * '.' + column_name = options[:select] || [connection.quote_table_name(table_name), primary_key] * '.' end if options[:distinct] @@ -182,7 +182,7 @@ module ActiveRecord sql << ", #{options[:group_field]} AS #{options[:group_alias]}" if options[:group] sql << " FROM (SELECT DISTINCT #{column_name}" if use_workaround - sql << " FROM #{table_name} " + sql << " FROM #{connection.quote_table_name(table_name)} " if merged_includes.any? join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, merged_includes, options[:joins], options[:ar_joins]) sql << join_dependency.join_associations.collect{|join| join.association_join }.join diff --git a/activerecord/test/reserved_word_test_mysql.rb b/activerecord/test/reserved_word_test_mysql.rb index c740a80e81..1a7b9a1ad5 100644 --- a/activerecord/test/reserved_word_test_mysql.rb +++ b/activerecord/test/reserved_word_test_mysql.rb @@ -141,6 +141,11 @@ class MysqlReservedWordTest < Test::Unit::TestCase assert_nothing_raised { Group.table_exists? } assert_nothing_raised { Group.columns } end + + # Calculations + def test_calculations_work_with_reserved_words + assert_nothing_raised { Group.count } + end #the following functions were added to DRY test cases |