diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 52ced36..3082517 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -158,9 +158,9 @@ module ActiveRecord end "INNER JOIN %s ON %s.%s = %s.%s %s #{@reflection.options[:joins]} #{custom_joins}" % [ - @reflection.through_reflection.table_name, + @reflection.through_reflection.quoted_table_name, @reflection.table_name, reflection_primary_key, - @reflection.through_reflection.table_name, source_primary_key, + @reflection.through_reflection.quoted_table_name, source_primary_key, polymorphic_join ] end diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index 05155f6..3a94a29 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -2,9 +2,11 @@ require "cases/helper" require 'models/post' require 'models/person' require 'models/reader' +require 'models/reference' +require 'models/job' class HasManyThroughAssociationsTest < ActiveRecord::TestCase - fixtures :posts, :readers, :people + fixtures :posts, :readers, :people, :references, :jobs def test_associate_existing assert_queries(2) { posts(:thinking);people(:david) } @@ -187,4 +189,8 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase post.people_with_callbacks.clear assert_equal (%w(Michael David Julian Roger) * 2).sort, log.last(8).collect(&:last).sort end + + def test_inner_join_with_quoted_table_name + assert_equal 2, people(:michael).jobs.size + end end