From 0925c6b6a06dd9fb5599d24ec9c2f4e11282bc12 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Sun, 19 Mar 2006 02:01:40 +0000 Subject: Allow has_many :through to work on has_many associations (closes #3864) [sco@scottraymond.net] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3964 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/reflection.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/reflection.rb') diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 3011ba6625..0d3333e0e1 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -156,7 +156,9 @@ module ActiveRecord # def source_reflection return nil unless through_reflection - @source_reflection ||= through_reflection.klass.reflect_on_association(source_reflection_name) + @source_reflection ||= \ + through_reflection.klass.reflect_on_association(source_reflection_name) || # has_many :through a :belongs_to + through_reflection.klass.reflect_on_association(name) # has_many :through a :has_many end def check_validity! @@ -183,7 +185,7 @@ module ActiveRecord if options[:class_name] options[:class_name] elsif through_reflection # get the class_name of the belongs_to association of the through reflection - through_reflection.klass.reflect_on_association(name.to_s.singularize.to_sym).class_name + source_reflection.class_name else class_name = name.to_s.camelize class_name = class_name.singularize if [ :has_many, :has_and_belongs_to_many ].include?(macro) -- cgit v1.2.3