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.rb59
1 files changed, 12 insertions, 47 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index face8e9200..70e2487891 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -179,8 +179,12 @@ module ActiveRecord
scope ? [scope] : []
end
+ def scope_chain
+ chain.map(&:scopes)
+ end
+
def constraints
- scope_chain.flatten
+ chain.map(&:scopes).flatten
end
def counter_cache_column
@@ -465,12 +469,6 @@ module ActiveRecord
false
end
- # An array of arrays of scopes. Each item in the outside array corresponds to a reflection
- # in the #chain.
- def scope_chain
- scope ? [[scope]] : [[]]
- end
-
def has_scope?
scope
end
@@ -820,30 +818,14 @@ module ActiveRecord
# but only Comment.tags will be represented in the #chain. So this method creates an array
# of scopes corresponding to the chain.
def scopes
- @sc ||= if scope
- source_reflection.scopes + through_reflection.scopes + [scope]
+ if scope
+ source_reflection.scopes + [scope]
else
- source_reflection.scopes + through_reflection.scopes
- end
-
- return @sc
- scope_chain = source_reflection.scopes
- scope_chain = through_reflection.scopes
-
- # Add to it the scope from this reflection (if any)
- scope_chain.first << scope if scope
-
- through_scope_chain = through_reflection.scope_chain.map(&:dup)
-
- if options[:source_type]
- through_scope_chain.first << source_type_lambda
+ source_reflection.scopes
end
-
- # Recursively fill out the rest of the array from the through reflection
- scope_chain + through_scope_chain
end
- def source_type_lambda
+ def source_type_scope
@source_type_lambda ||= begin
type = foreign_type
source_type = options[:source_type]
@@ -853,24 +835,6 @@ module ActiveRecord
end
end
- def scope_chain
- @scope_chain ||= begin
- scope_chain = source_reflection.scope_chain.map(&:dup)
-
- # Add to it the scope from this reflection (if any)
- scope_chain.first << scope if scope
-
- through_scope_chain = through_reflection.scope_chain.map(&:dup)
-
- if options[:source_type]
- through_scope_chain.first << source_type_lambda
- end
-
- # Recursively fill out the rest of the array from the through reflection
- scope_chain + through_scope_chain
- end
- end
-
def has_scope?
scope || options[:source_type] ||
source_reflection.has_scope? ||
@@ -1043,10 +1007,11 @@ module ActiveRecord
end
def scopes
+ scopes = @previous_reflection.scopes
if @previous_reflection.options[:source_type]
- return super + [@previous_reflection.source_type_lambda]
+ scopes + [@previous_reflection.source_type_scope]
else
- return super
+ scopes
end
end