From 19672421ac11c6432477246aca5414933b8d94cd Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Tue, 27 Feb 2018 02:47:32 +0900 Subject: Partly revert 91b30a001b79096b60d9424a4664a417dce0b767 Actually `reflection.klass` should be valid AR model unless `polymorphic?`. Previously it worked limitedly by ignoring `NameError` even if `reflection.klass` is invalid, and our isolated testing depends on the limited working. Probably we should also check the klass validity in `check_validity!` properly. Until that time, I restored the error suppression for now. Closes #32113. --- activerecord/lib/active_record/reflection.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 71afbc1041..42b451241d 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -611,7 +611,13 @@ module ActiveRecord if can_find_inverse_of_automatically?(self) inverse_name = ActiveSupport::Inflector.underscore(options[:as] || active_record.name.demodulize).to_sym - reflection = klass._reflect_on_association(inverse_name) + begin + reflection = klass._reflect_on_association(inverse_name) + rescue NameError + # Give up: we couldn't compute the klass type so we won't be able + # to find any associations either. + reflection = false + end if valid_inverse_reflection?(reflection) return inverse_name -- cgit v1.2.3