diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-02-27 02:47:32 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-02-27 03:31:35 +0900 |
commit | 19672421ac11c6432477246aca5414933b8d94cd (patch) | |
tree | b37d081656e7ad585b55ba369406dd39d67bbdb3 /activerecord | |
parent | c2a2b84d8d9185127d59a4760efb7356aea25af1 (diff) | |
download | rails-19672421ac11c6432477246aca5414933b8d94cd.tar.gz rails-19672421ac11c6432477246aca5414933b8d94cd.tar.bz2 rails-19672421ac11c6432477246aca5414933b8d94cd.zip |
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.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 8 |
1 files changed, 7 insertions, 1 deletions
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 |