aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/inner_join_association_test.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-10-24 21:47:11 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-10-24 21:47:11 +0900
commit019583e939f6615590a4d6c1e4370e4e973fedff (patch)
tree8a71f645e7ca081451a0ae901afc70857e32a229 /activerecord/test/cases/associations/inner_join_association_test.rb
parentd147ed02a00fe50f3428962dfadb5de076c56a5e (diff)
downloadrails-019583e939f6615590a4d6c1e4370e4e973fedff.tar.gz
rails-019583e939f6615590a4d6c1e4370e4e973fedff.tar.bz2
rails-019583e939f6615590a4d6c1e4370e4e973fedff.zip
Ensure associations doesn't table name collide with aliased joins
Currently alias tracker only refer a table name, doesn't respect an alias name. Should use `join.left.name` rather than `join.left.table_name`.
Diffstat (limited to 'activerecord/test/cases/associations/inner_join_association_test.rb')
-rw-r--r--activerecord/test/cases/associations/inner_join_association_test.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/inner_join_association_test.rb b/activerecord/test/cases/associations/inner_join_association_test.rb
index eb85acf37e..7be875fec6 100644
--- a/activerecord/test/cases/associations/inner_join_association_test.rb
+++ b/activerecord/test/cases/associations/inner_join_association_test.rb
@@ -37,6 +37,14 @@ class InnerJoinAssociationTest < ActiveRecord::TestCase
assert_match(/agents_people_2/i, sql)
end
+ def test_construct_finder_sql_does_not_table_name_collide_with_aliased_joins
+ people = Person.arel_table
+ agents = people.alias("agents_people")
+ constraint = agents[:primary_contact_id].eq(people[:id])
+ sql = Person.joins(:agents).joins(agents.create_join(agents, agents.create_on(constraint))).to_sql
+ assert_match(/agents_people_2/i, sql)
+ end
+
def test_construct_finder_sql_ignores_empty_joins_hash
sql = Author.joins({}).to_sql
assert_no_match(/JOIN/i, sql)