aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2014-12-20 18:57:06 +0900
committerTakashi Kokubun <takashikkbn@gmail.com>2016-01-31 02:30:09 +0900
commit12e9e38d9a550f77936c29d14a8b8156cdfa81be (patch)
treee410baff3108d7f6cf68c8b67a2bd8528400793b /activerecord/lib/active_record/associations
parenta59212709c1daddf1c3703198cc3e45fd5226baf (diff)
downloadrails-12e9e38d9a550f77936c29d14a8b8156cdfa81be.tar.gz
rails-12e9e38d9a550f77936c29d14a8b8156cdfa81be.tar.bz2
rails-12e9e38d9a550f77936c29d14a8b8156cdfa81be.zip
Allow `joins` to be unscoped
Diffstat (limited to 'activerecord/lib/active_record/associations')
-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 be65cf318c..8e5b032a93 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