diff options
author | Matt Jones <al2o3cr@gmail.com> | 2014-02-21 17:58:40 -0500 |
---|---|---|
committer | Matt Jones <al2o3cr@gmail.com> | 2014-02-21 17:58:40 -0500 |
commit | 70a5e5638bfd3b2543bb9d4805cbefec84b6b1ce (patch) | |
tree | a0d586612e71950a8dca78b1aa21ea0a0f0cf83f /activerecord/lib/active_record | |
parent | 467cb908dd5f40cbfefe41b93e219682a3ced535 (diff) | |
download | rails-70a5e5638bfd3b2543bb9d4805cbefec84b6b1ce.tar.gz rails-70a5e5638bfd3b2543bb9d4805cbefec84b6b1ce.tar.bz2 rails-70a5e5638bfd3b2543bb9d4805cbefec84b6b1ce.zip |
Pass a base relation to build_default_scope when joining
This allows the default scope to be built using the current table alias.
Resolves #12770
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency/join_association.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/scoping/default.rb | 6 |
2 files changed, 4 insertions, 4 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 cee3c9999f..1d923ecc09 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -54,7 +54,7 @@ module ActiveRecord end scope_chain_index += 1 - scope_chain_items.concat [klass.send(:build_default_scope)].compact + scope_chain_items.concat [klass.send(:build_default_scope, ActiveRecord::Relation.create(klass, table))].compact rel = scope_chain_items.inject(scope_chain_items.shift) do |left, right| left.merge right diff --git a/activerecord/lib/active_record/scoping/default.rb b/activerecord/lib/active_record/scoping/default.rb index 01fec31544..8ca5e8d6f6 100644 --- a/activerecord/lib/active_record/scoping/default.rb +++ b/activerecord/lib/active_record/scoping/default.rb @@ -93,14 +93,14 @@ module ActiveRecord self.default_scopes += [scope] end - def build_default_scope # :nodoc: + def build_default_scope(base_rel = relation) # :nodoc: if !Base.is_a?(method(:default_scope).owner) # The user has defined their own default scope method, so call that evaluate_default_scope { default_scope } elsif default_scopes.any? evaluate_default_scope do - default_scopes.inject(relation) do |default_scope, scope| - default_scope.merge(unscoped { scope.call }) + default_scopes.inject(base_rel) do |default_scope, scope| + default_scope.merge(base_rel.scoping { scope.call }) end end end |