diff options
author | Rick Olson <technoweenie@gmail.com> | 2006-03-19 00:53:24 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2006-03-19 00:53:24 +0000 |
commit | 57af961a80ee01d1876dfc50d93544906a995617 (patch) | |
tree | 571058edf37e0903d5bf72bea16925d36a486eda /activerecord/lib/active_record/associations.rb | |
parent | 49efa02b9e8d868b2d28a3db76269d8b8fcde0a6 (diff) | |
download | rails-57af961a80ee01d1876dfc50d93544906a995617.tar.gz rails-57af961a80ee01d1876dfc50d93544906a995617.tar.bz2 rails-57af961a80ee01d1876dfc50d93544906a995617.zip |
Raise error when trying to select many polymorphic objects with has_many :through or :include (closes #4226) [josh@hasmanythrough.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3961 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index ede8fd1223..9d4ba329bc 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -9,6 +9,49 @@ require 'active_record/associations/has_and_belongs_to_many_association' require 'active_record/deprecated_associations' module ActiveRecord + class HasManyThroughAssociationNotFoundError < ActiveRecordError + def initialize(reflection) + @reflection = reflection + end + + def message + "Could not find the association '#{@reflection.options[:through]}' in model #{@reflection.klass}" + end + end + + class HasManyThroughAssociationPolymorphicError < ActiveRecordError + def initialize(owner_class_name, reflection, source_reflection) + @owner_class_name = owner_class_name + @reflection = reflection + @source_reflection = source_reflection + end + + def message + "Cannot have a has_many :through association '#{@owner_class_name}##{@reflection.name}' on the polymorphic object '#{@source_reflection.class_name}##{@source_reflection.name}'." + end + end + + class HasManyThroughSourceAssociationNotFoundError < ActiveRecordError + def initialize(through_reflection, source_reflection_name) + @through_reflection = through_reflection + @source_reflection_name = source_reflection_name + end + + def message + "Could not find the source association '#{@source_reflection_name}' in model #{@through_reflection.klass}" + end + end + + class EagerLoadPolymorphicError < ActiveRecordError + def initialize(reflection) + @reflection = reflection + end + + def message + "Can not eagerly load the polymorphic association '#{@reflection.name}'" + end + end + module Associations # :nodoc: def self.append_features(base) super @@ -1204,6 +1247,11 @@ module ActiveRecord delegate :options, :klass, :to => :reflection def initialize(reflection, join_dependency, parent = nil) + reflection.check_validity! + if reflection.options[:polymorphic] + raise EagerLoadPolymorphicError.new(reflection) + end + super(reflection.klass) @parent = parent @reflection = reflection |