aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/reflection.rb24
-rw-r--r--activerecord/test/cases/reflection_test.rb2
2 files changed, 3 insertions, 23 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 1f3ace93a9..e801bc4afa 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -409,33 +409,13 @@ module ActiveRecord
# Returns an array of reflections which are involved in this association. Each item in the
# array corresponds to a table which will be part of the query for this association.
#
- # If the source reflection is itself a ThroughReflection, then we don't include self in
- # the chain, but just defer to the source reflection.
- #
# The chain is built by recursively calling #chain on the source reflection and the through
# reflection. The base case for the recursion is a normal association, which just returns
# [self] as its #chain.
def chain
@chain ||= begin
- if source_reflection.source_reflection
- # If the source reflection has its own source reflection, then the chain must start
- # by getting us to that source reflection.
- chain = source_reflection.chain
- else
- # If the source reflection does not go through another reflection, then we can get
- # to this reflection directly, and so start the chain here
- #
- # It is important to use self, rather than the source_reflection, because self
- # may has a :source_type option which needs to be used.
- #
- # FIXME: Not sure this is correct justification now that we have #conditions
- chain = [self]
- end
-
- # Recursively build the rest of the chain
- chain += through_reflection.chain
-
- # Finally return the completed chain
+ chain = source_reflection.chain + through_reflection.chain
+ chain[0] = self # Use self so we don't lose the information from :source_type
chain
end
end
diff --git a/activerecord/test/cases/reflection_test.rb b/activerecord/test/cases/reflection_test.rb
index 4b881969cc..918bc0a842 100644
--- a/activerecord/test/cases/reflection_test.rb
+++ b/activerecord/test/cases/reflection_test.rb
@@ -204,7 +204,7 @@ class ReflectionTest < ActiveRecord::TestCase
def test_chain
expected = [
- Author.reflect_on_association(:essay_categories),
+ Organization.reflect_on_association(:author_essay_categories),
Author.reflect_on_association(:essays),
Organization.reflect_on_association(:authors)
]