aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2016-02-11 11:33:30 -0700
committerSean Griffin <sean@seantheprogrammer.com>2016-02-11 11:33:30 -0700
commit6fedc7d56a580d1ef7e923d95865bd99626d2f21 (patch)
treee796622611491add0c8349d3fb1b9296d92a3cc8 /activerecord/lib/active_record
parent848f70e18406e3c9bd952074ce627e82a474dda7 (diff)
parent12e9e38d9a550f77936c29d14a8b8156cdfa81be (diff)
downloadrails-6fedc7d56a580d1ef7e923d95865bd99626d2f21.tar.gz
rails-6fedc7d56a580d1ef7e923d95865bd99626d2f21.tar.bz2
rails-6fedc7d56a580d1ef7e923d95865bd99626d2f21.zip
Merge pull request #18109 from k0kubun/unscoped-joins
Allow `joins` to be unscoped Fixes #13775
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/associations/join_dependency/join_association.rb18
1 files changed, 12 insertions, 6 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 708b3af5bd..c5fbe0d1d1 100644
--- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -54,12 +54,18 @@ module ActiveRecord
end
scope_chain_index += 1
- relation = ActiveRecord::Relation.create(
- klass,
- table,
- predicate_builder,
- )
- scope_chain_items.concat [klass.send(:build_default_scope, relation)].compact
+ klass_scope =
+ if klass.current_scope
+ klass.current_scope.clone
+ else
+ relation = ActiveRecord::Relation.create(
+ klass,
+ table,
+ predicate_builder,
+ )
+ klass.send(:build_default_scope, relation)
+ end
+ scope_chain_items.concat [klass_scope].compact
rel = scope_chain_items.inject(scope_chain_items.shift) do |left, right|
left.merge right