diff options
author | Rick Olson <technoweenie@gmail.com> | 2006-03-18 22:38:49 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2006-03-18 22:38:49 +0000 |
commit | fbd1e01bd6ca1b093811b0781d85f53850df12e3 (patch) | |
tree | cad9138fbecb159c9820f5aaed2d3d8ffdac0915 /activerecord/lib/active_record/reflection.rb | |
parent | 1e7ce13b372e554438aa58c466dc100ef174ae9e (diff) | |
download | rails-fbd1e01bd6ca1b093811b0781d85f53850df12e3.tar.gz rails-fbd1e01bd6ca1b093811b0781d85f53850df12e3.tar.bz2 rails-fbd1e01bd6ca1b093811b0781d85f53850df12e3.zip |
Fix that has_many :through honors the foreign key set by the belongs_to association in the join model (closes #4259) [andylien@gmail.com / Rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3954 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/reflection.rb')
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index e54e38e184..e56682ec92 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -140,6 +140,10 @@ module ActiveRecord end end + def through_reflection + @through_reflection ||= options[:through] ? active_record.reflect_on_association(options[:through]) : false + end + private def name_to_class_name(name) if name =~ /::/ @@ -147,6 +151,8 @@ module ActiveRecord else 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 else class_name = name.to_s.camelize class_name = class_name.singularize if [ :has_many, :has_and_belongs_to_many ].include?(macro) |