From ea09bf5419ec752dd020d26b03533afa457d09d6 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Tue, 18 Jul 2017 04:15:45 +0900 Subject: Fix `JoinDependency` with using a custom table Without this fix, `JoinDependency` doesn't use a custom table alias: ``` % ARCONN=sqlite3 be ruby -w -Itest test/cases/relations_test.rb -n test_using_a_custom_table_with_joins_affects_the_wheres Using sqlite3 Run options: -n test_using_a_custom_table_with_joins_affects_the_wheres --seed 14531 E Error:RelationTest#test_using_a_custom_table_with_joins_affects_the_wheres: ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: posts.author_id: SELECT "omg_posts".* FROM "posts" "omg_posts" INNER JOIN "authors" ON "authors"."id" = "posts"."author_id" WHERE "omg_posts"."title" = ? LIMIT ? ``` --- activerecord/lib/active_record/relation/merger.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'activerecord/lib/active_record/relation/merger.rb') diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb index 5dac00724a..6251f6fc33 100644 --- a/activerecord/lib/active_record/relation/merger.rb +++ b/activerecord/lib/active_record/relation/merger.rb @@ -119,9 +119,10 @@ module ActiveRecord end end - join_dependency = ActiveRecord::Associations::JoinDependency.new(other.klass, - joins_dependency, - []) + join_dependency = ActiveRecord::Associations::JoinDependency.new( + other.klass, other.table, joins_dependency, [] + ) + relation.joins! rest @relation = relation.joins join_dependency -- cgit v1.2.3