public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fix has many through not quoting table names [#1163 state:resolved]

Signed-off-by: Frederick Cheung <frederick.cheung@gmail.com>
Karthik Krishnan (author)
Sat Dec 20 12:52:48 -0800 2008
lifo (committer)
Sat Dec 20 13:08:51 -0800 2008
commit  75a133f92ff7e27b83032babf829d8a58803bb3c
tree    b6d68bff1f29febd1eb3b91987d6aaff9a4963fc
parent  c092dbef50ba207174a94b7e0beb7782a3d86649
...
2198
2199
2200
2201
 
2202
2203
2204
...
2198
2199
2200
 
2201
2202
2203
2204
0
@@ -2198,7 +2198,7 @@ module ActiveRecord
0
             protected
0
 
0
               def aliased_table_name_for(name, suffix = nil)
0
-                if !parent.table_joins.blank? && parent.table_joins.to_s.downcase =~ %r{join(\s+\w+)?\s+#{name.downcase}\son}
0
+                if !parent.table_joins.blank? && parent.table_joins.to_s.downcase =~ %r{join(\s+\w+)?\s+#{active_record.connection.quote_table_name name.downcase}\son}
0
                   @join_dependency.table_aliases[name] += 1
0
                 end
0
 
...
160
161
162
163
164
165
 
 
 
166
167
168
...
160
161
162
 
 
 
163
164
165
166
167
168
0
@@ -160,9 +160,9 @@ module ActiveRecord
0
           end
0
 
0
           "INNER JOIN %s ON %s.%s = %s.%s %s #{@reflection.options[:joins]} #{custom_joins}" % [
0
-            @reflection.through_reflection.table_name,
0
-            @reflection.table_name, reflection_primary_key,
0
-            @reflection.through_reflection.table_name, source_primary_key,
0
+            @reflection.through_reflection.quoted_table_name,
0
+            @reflection.quoted_table_name, reflection_primary_key,
0
+            @reflection.through_reflection.quoted_table_name, source_primary_key,
0
             polymorphic_join
0
           ]
0
         end
...
204
205
206
 
 
 
 
207
208
209
...
204
205
206
207
208
209
210
211
212
213
0
@@ -204,6 +204,10 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
0
     assert_equal 2, people(:michael).posts.count(:include => :readers)
0
   end
0
 
0
+  def test_inner_join_with_quoted_table_name
0
+    assert_equal 2, people(:michael).jobs.size
0
+  end
0
+
0
   def test_get_ids
0
     assert_equal [posts(:welcome).id, posts(:authorless).id].sort, people(:michael).post_ids.sort
0
   end

Comments