aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/inheritance.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-03-24 14:12:24 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-03-24 14:12:24 -0300
commitd024bad4d1f8307a66fd6684dc658fddee37147e (patch)
tree132b23f4cab25c3571cb5528e4f3a04e72f9964d /activerecord/lib/active_record/inheritance.rb
parent5cfa6a8ab997089c3012a82052c8c317b2e095f5 (diff)
downloadrails-d024bad4d1f8307a66fd6684dc658fddee37147e.tar.gz
rails-d024bad4d1f8307a66fd6684dc658fddee37147e.tar.bz2
rails-d024bad4d1f8307a66fd6684dc658fddee37147e.zip
Revert "Merge pull request #19500 from ccutrer/dry_sti_subclass_finding"
This reverts commit 5cfa6a8ab997089c3012a82052c8c317b2e095f5, reversing changes made to bfd5bf8313e6ea0bb2eccb68ee5076bb63f0b2db. Reason: This broken travis build.
Diffstat (limited to 'activerecord/lib/active_record/inheritance.rb')
-rw-r--r--activerecord/lib/active_record/inheritance.rb38
1 files changed, 19 insertions, 19 deletions
diff --git a/activerecord/lib/active_record/inheritance.rb b/activerecord/lib/active_record/inheritance.rb
index d3ef88288c..24098f72dc 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 && subclass != self
+ if subclass
subclass.new(*args, &block)
else
super
@@ -167,23 +167,17 @@ module ActiveRecord
end
def find_sti_class(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}"
+ if store_full_sti_class
+ ActiveSupport::Dependencies.constantize(type_name)
+ else
+ compute_type(type_name)
end
- subclass
+ 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
def type_condition(table = arel_table)
@@ -204,8 +198,14 @@ module ActiveRecord
def subclass_from_attributes(attrs)
subclass_name = attrs.with_indifferent_access[inheritance_column]
- if subclass_name.present?
- find_sti_class(subclass_name)
+ if subclass_name.present? && subclass_name != self.name
+ subclass = subclass_name.safe_constantize
+
+ unless descendants.include?(subclass)
+ raise ActiveRecord::SubclassNotFound.new("Invalid single-table inheritance type: #{subclass_name} is not a subclass of #{name}")
+ end
+
+ subclass
end
end
end