aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-05-15 22:24:57 +0900
committerGitHub <noreply@github.com>2019-05-15 22:24:57 +0900
commit13d6aa3a7b70bca66c4abda7721329ad1863c24c (patch)
treef1ce8b480b853df1f32cd7ab5f7e92a0d62e1508 /activerecord/lib/active_record
parenta2708473b150b30a00c80d64f57a8c4b41a32fcc (diff)
parentec6dfdc8d21031e07dd381853ff37fcc63f8bd86 (diff)
downloadrails-13d6aa3a7b70bca66c4abda7721329ad1863c24c.tar.gz
rails-13d6aa3a7b70bca66c4abda7721329ad1863c24c.tar.bz2
rails-13d6aa3a7b70bca66c4abda7721329ad1863c24c.zip
Merge pull request #36284 from kamipo/fix_eager_loading_with_string_joins
Fix eager loading associations with string joins not to raise NoMethodError
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/associations/join_dependency/join_association.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
index ca0305abbb..6a7e92dc28 100644
--- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -44,8 +44,7 @@ module ActiveRecord
unless others.empty?
joins.concat arel.join_sources
- right = joins.last.right
- right.expr.children.concat(others)
+ append_constraints(joins.last, others)
end
# The current table in this iteration becomes the foreign table in the next
@@ -65,6 +64,16 @@ module ActiveRecord
@readonly = reflection.scope && reflection.scope_for(base_klass.unscoped).readonly_value
end
+
+ private
+ def append_constraints(join, constraints)
+ if join.is_a?(Arel::Nodes::StringJoin)
+ join_string = table.create_and(constraints.unshift(join.left))
+ join.left = Arel.sql(base_klass.connection.visitor.compile(join_string))
+ else
+ join.right.expr.children.concat(constraints)
+ end
+ end
end
end
end