diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index cb240229a5be7b9e293a34bd7aca7e9251540432..71993a4fe4873d235e64850b8e72e18cd895a6d9 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -175,6 +175,8 @@ def join_keys(association_klass) JoinKeys.new(foreign_key, active_record_primary_key) end + # Returns a list of scopes that should be applied for this Reflection + # object when querying the database. def scopes scope ? [scope] : [] end @@ -798,31 +800,8 @@ def clear_association_scope_cache # :nodoc: through_reflection.clear_association_scope_cache end - # Consider the following example: - # - # class Person - # has_many :articles - # has_many :comment_tags, through: :articles - # end - # - # class Article - # has_many :comments - # has_many :comment_tags, through: :comments, source: :tags - # end - # - # class Comment - # has_many :tags - # end - # - # There may be scopes on Person.comment_tags, Article.comment_tags and/or Comment.tags, - # but only Comment.tags will be represented in the #chain. So this method creates an array - # of scopes corresponding to the chain. def scopes - if scope - source_reflection.scopes + [scope] - else - source_reflection.scopes - end + source_reflection.scopes + super end def source_type_scope