diff options
author | Rick Olson <technoweenie@gmail.com> | 2007-03-13 05:23:18 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2007-03-13 05:23:18 +0000 |
commit | e3dab67c44ed047cc91ccfcc17c5ee2bb9997be3 (patch) | |
tree | 5acc906178f850d70706a24c5ca47a3acdd43097 /activerecord/lib/active_record/reflection.rb | |
parent | 2823a56f14edac7e9012484d375f23c89405d725 (diff) | |
download | rails-e3dab67c44ed047cc91ccfcc17c5ee2bb9997be3.tar.gz rails-e3dab67c44ed047cc91ccfcc17c5ee2bb9997be3.tar.bz2 rails-e3dab67c44ed047cc91ccfcc17c5ee2bb9997be3.zip |
Allow a polymorphic :source for has_many :through associations. Closes #7143 [protocool]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6408 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/reflection.rb')
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 2adadb29c5..62184eeff2 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -178,8 +178,12 @@ module ActiveRecord if source_reflection.nil? raise HasManyThroughSourceAssociationNotFoundError.new(self) end + + if options[:source_type] && source_reflection.options[:polymorphic].nil? + raise HasManyThroughAssociationPointlessSourceTypeError.new(active_record.name, self, source_reflection) + end - if source_reflection.options[:polymorphic] + if source_reflection.options[:polymorphic] && options[:source_type].nil? raise HasManyThroughAssociationPolymorphicError.new(active_record.name, self, source_reflection) end @@ -193,7 +197,7 @@ module ActiveRecord def derive_class_name # get the class_name of the belongs_to association of the through reflection if through_reflection - source_reflection.class_name + options[:source_type] || 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) |