diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2015-10-29 09:21:57 -0600 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2015-10-29 09:22:45 -0600 |
commit | 4a2d586cfcd58c0d65dfe7e603e4e5e84418801e (patch) | |
tree | 0ff5b1bfb55b6d209be0d72c90fc2b6d14874342 /activerecord/lib/active_record | |
parent | 59ec8a592d7125f12e33a8aba22b4d2fc4ae301f (diff) | |
parent | 7c0f8c64fa1e8e055e2077255843f149e600024b (diff) | |
download | rails-4a2d586cfcd58c0d65dfe7e603e4e5e84418801e.tar.gz rails-4a2d586cfcd58c0d65dfe7e603e4e5e84418801e.tar.bz2 rails-4a2d586cfcd58c0d65dfe7e603e4e5e84418801e.zip |
Fix merge conflicts from #19501
I'm making this commit separately because this has failing tests and
style nitpicks that I'd like to make as individual commits, to make the
changes I'm making explicit.
We still want a single merge commit at the end, however.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/inheritance.rb | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/activerecord/lib/active_record/inheritance.rb b/activerecord/lib/active_record/inheritance.rb index c26842014d..53a9a9b797 100644 --- a/activerecord/lib/active_record/inheritance.rb +++ b/activerecord/lib/active_record/inheritance.rb @@ -55,7 +55,7 @@ module ActiveRecord subclass = subclass_from_attributes(attrs) end - if subclass + if subclass && subclass != self subclass.new(*args, &block) else super @@ -167,17 +167,23 @@ module ActiveRecord end def find_sti_class(type_name) - if store_full_sti_class - ActiveSupport::Dependencies.constantize(type_name) - else - compute_type(type_name) + subclass = begin + if store_full_sti_class + ActiveSupport::Dependencies.constantize(type_name) + else + compute_type(type_name) + end + rescue NameError + raise SubclassNotFound, + "The single-table inheritance mechanism failed to locate the subclass: '#{type_name}'. " + + "This error is raised because the column '#{inheritance_column}' is reserved for storing the class in case of inheritance. " + + "Please rename this column if you didn't intend it to be used for storing the inheritance class " + + "or overwrite #{name}.inheritance_column to use another column for that information." + end + unless subclass == self || descendants.include?(subclass) + raise SubclassNotFound, "Invalid single-table inheritance type: #{type_name} is not a subclass of #{name}" end - rescue NameError - raise SubclassNotFound, - "The single-table inheritance mechanism failed to locate the subclass: '#{type_name}'. " + - "This error is raised because the column '#{inheritance_column}' is reserved for storing the class in case of inheritance. " + - "Please rename this column if you didn't intend it to be used for storing the inheritance class " + - "or overwrite #{name}.inheritance_column to use another column for that information." + subclass end def type_condition(table = arel_table) @@ -199,15 +205,7 @@ module ActiveRecord subclass_name = attrs.with_indifferent_access[inheritance_column] if subclass_name.present? - subclass = find_sti_class(subclass_name) - - if subclass.name != self.name - unless descendants.include?(subclass) - raise ActiveRecord::SubclassNotFound.new("Invalid single-table inheritance type: #{subclass.name} is not a subclass of #{name}") - end - - subclass - end + find_sti_class(subclass_name) end end end |