diff options
author | Murray Steele <muz@h-lame.com> | 2009-12-28 14:13:33 +0100 |
---|---|---|
committer | Eloy Duran <eloy.de.enige@gmail.com> | 2009-12-28 15:12:17 +0100 |
commit | ff508640e28914da2b546f6a8c9f215bab201b61 (patch) | |
tree | ae952ef0dad923d9e7b3e5b36e2d74ba9f20867b /activerecord/lib | |
parent | 6a74ee7f4deea4a44520d3fcc9120e0bb848823f (diff) | |
download | rails-ff508640e28914da2b546f6a8c9f215bab201b61.tar.gz rails-ff508640e28914da2b546f6a8c9f215bab201b61.tar.bz2 rails-ff508640e28914da2b546f6a8c9f215bab201b61.zip |
Make polymorphic_inverse_of in Reflection throw an InverseOfAssociationNotFoundError if the supplied class doesn't have the appropriate association. [#3520 state:resolved]
Signed-off-by: Eloy Duran <eloy.de.enige@gmail.com>
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 10 |
2 files changed, 7 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index c23c9f63f1..ff8c63bc91 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -3,8 +3,8 @@ require 'active_support/core_ext/enumerable' module ActiveRecord class InverseOfAssociationNotFoundError < ActiveRecordError #:nodoc: - def initialize(reflection) - super("Could not find the inverse association for #{reflection.name} (#{reflection.options[:inverse_of].inspect} in #{reflection.class_name})") + def initialize(reflection, associated_class = nil) + super("Could not find the inverse association for #{reflection.name} (#{reflection.options[:inverse_of].inspect} in #{associated_class.nil? ? reflection.class_name : associated_class.name})") end end diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 72f7df32c7..b751c9ad68 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -239,16 +239,16 @@ module ActiveRecord def inverse_of if has_inverse? @inverse_of ||= klass.reflect_on_association(options[:inverse_of]) - else - nil end end def polymorphic_inverse_of(associated_class) if has_inverse? - associated_class.reflect_on_association(options[:inverse_of]) - else - nil + if inverse_relationship = associated_class.reflect_on_association(options[:inverse_of]) + inverse_relationship + else + raise InverseOfAssociationNotFoundError.new(self, associated_class) + end end end |