aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/reflection.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/reflection.rb')
-rw-r--r--activerecord/lib/active_record/reflection.rb22
1 files changed, 5 insertions, 17 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index e35049bb41..49ddcaecdf 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -214,7 +214,7 @@ module ActiveRecord
def join_scopes(table, predicate_builder) # :nodoc:
if scope
- [build_scope(table, predicate_builder).instance_exec(&scope)]
+ [scope_for(build_scope(table, predicate_builder))]
else
[]
end
@@ -391,8 +391,8 @@ module ActiveRecord
active_record == other_aggregation.active_record
end
- def scope_for(klass)
- scope ? klass.unscoped.instance_exec(nil, &scope) : klass.unscoped
+ def scope_for(relation, owner = nil)
+ relation.instance_exec(owner, &scope) || relation
end
private
@@ -1036,20 +1036,12 @@ module ActiveRecord
def scopes
scopes = @previous_reflection.scopes
- if @previous_reflection.options[:source_type]
- scopes + [@previous_reflection.source_type_scope]
- else
- scopes
- end
+ scopes << @previous_reflection.source_type_scope
end
def join_scopes(table, predicate_builder) # :nodoc:
scopes = @previous_reflection.join_scopes(table, predicate_builder) + super
- if @previous_reflection.options[:source_type]
- scopes + [@previous_reflection.source_type_scope]
- else
- scopes
- end
+ scopes << @previous_reflection.source_type_scope
end
def klass
@@ -1100,10 +1092,6 @@ module ActiveRecord
@reflection.constraints
end
- def alias_candidate(name)
- "#{plural_name}_#{name}_join"
- end
-
def alias_name
Arel::Table.new(table_name, type_caster: klass.type_caster)
end