Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix has many through not quoting table names [#1163 state:resolved]

Signed-off-by: Frederick Cheung <frederick.cheung@gmail.com>
  • Loading branch information...
commit 75a133f92ff7e27b83032babf829d8a58803bb3c 1 parent c092dbe
Karthik Krishnan authored lifo committed
View
2  activerecord/lib/active_record/associations.rb
@@ -2198,7 +2198,7 @@ def association_join
protected
def aliased_table_name_for(name, suffix = nil)
- if !parent.table_joins.blank? && parent.table_joins.to_s.downcase =~ %r{join(\s+\w+)?\s+#{name.downcase}\son}
+ 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}
@join_dependency.table_aliases[name] += 1
end
View
6 activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -160,9 +160,9 @@ def construct_joins(custom_joins = nil)
end
"INNER JOIN %s ON %s.%s = %s.%s %s #{@reflection.options[:joins]} #{custom_joins}" % [
- @reflection.through_reflection.table_name,
- @reflection.table_name, reflection_primary_key,
- @reflection.through_reflection.table_name, source_primary_key,
+ @reflection.through_reflection.quoted_table_name,
+ @reflection.quoted_table_name, reflection_primary_key,
+ @reflection.through_reflection.quoted_table_name, source_primary_key,
polymorphic_join
]
end
View
4 activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -204,6 +204,10 @@ def test_count_with_include_should_alias_join_table
assert_equal 2, people(:michael).posts.count(:include => :readers)
end
+ def test_inner_join_with_quoted_table_name
+ assert_equal 2, people(:michael).jobs.size
+ end
+
def test_get_ids
assert_equal [posts(:welcome).id, posts(:authorless).id].sort, people(:michael).post_ids.sort
end
Please sign in to comment.
Something went wrong with that request. Please try again.