From a5fded3e88147769f4461d36bd60764ebcb95bc3 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 5 Dec 2007 02:30:30 +0000 Subject: [PATCH] Fix that options[:from] table names should never be quoted [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8270 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/associations.rb | 2 +- activerecord/test/associations/eager_test.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index de1ca24d6d..e9a1eb67b9 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1247,7 +1247,7 @@ module ActiveRecord def construct_finder_sql_with_included_associations(options, join_dependency) scope = scope(:find) - sql = "SELECT #{column_aliases(join_dependency)} FROM #{connection.quote_table_name((scope && scope[:from]) || options[:from] || table_name)} " + sql = "SELECT #{column_aliases(join_dependency)} FROM #{(scope && scope[:from]) || options[:from] || quoted_table_name} " sql << join_dependency.join_associations.collect{|join| join.association_join }.join add_joins!(sql, options, scope) diff --git a/activerecord/test/associations/eager_test.rb b/activerecord/test/associations/eager_test.rb index 75948ab59f..048f13b8b2 100644 --- a/activerecord/test/associations/eager_test.rb +++ b/activerecord/test/associations/eager_test.rb @@ -37,6 +37,17 @@ class EagerAssociationTest < Test::Unit::TestCase end end + def test_with_two_tables_in_from_without_getting_double_quoted + posts = Post.find(:all, + :select => "posts.*", + :from => "posts, authors", + :include => :comments, + :conditions => "posts.author_id = authors.id" + ) + + assert_equal 2, posts.first.comments.size + end + def test_loading_with_multiple_associations posts = Post.find(:all, :include => [ :comments, :author, :categories ], :order => "posts.id") assert_equal 2, posts.first.comments.size