aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/reflection.rb
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-03-19 02:01:40 +0000
committerRick Olson <technoweenie@gmail.com>2006-03-19 02:01:40 +0000
commit0925c6b6a06dd9fb5599d24ec9c2f4e11282bc12 (patch)
treee7ef51eb0343a1f6a255da151e458502869cd105 /activerecord/lib/active_record/reflection.rb
parent8463cd646ec5b8f439577a7c2ca225179709b5ed (diff)
downloadrails-0925c6b6a06dd9fb5599d24ec9c2f4e11282bc12.tar.gz
rails-0925c6b6a06dd9fb5599d24ec9c2f4e11282bc12.tar.bz2
rails-0925c6b6a06dd9fb5599d24ec9c2f4e11282bc12.zip
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
Diffstat (limited to 'activerecord/lib/active_record/reflection.rb')
-rw-r--r--activerecord/lib/active_record/reflection.rb6
1 files changed, 4 insertions, 2 deletions
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)