aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/reflection.rb14
1 files changed, 4 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 101ac2d33a..8950be1ab7 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -611,13 +611,7 @@ module ActiveRecord
if can_find_inverse_of_automatically?(self)
inverse_name = ActiveSupport::Inflector.underscore(options[:as] || active_record.name.demodulize).to_sym
- begin
- reflection = klass._reflect_on_association(inverse_name)
- rescue ArgumentError
- # Give up: we couldn't compute the klass type so we won't be able
- # to find any associations either.
- reflection = false
- end
+ reflection = klass._reflect_on_association(inverse_name)
if valid_inverse_reflection?(reflection)
return inverse_name
@@ -629,9 +623,6 @@ module ActiveRecord
# +automatic_inverse_of+ method is a valid reflection. We must
# make sure that the reflection's active_record name matches up
# with the current reflection's klass name.
- #
- # Note: klass will always be valid because when there's a NameError
- # from calling +klass+, +reflection+ will already be set to false.
def valid_inverse_reflection?(reflection)
reflection &&
klass <= reflection.active_record &&
@@ -735,6 +726,9 @@ module ActiveRecord
end
private
+ def can_find_inverse_of_automatically?(_)
+ !polymorphic? && super
+ end
def calculate_constructable(macro, options)
!polymorphic?