aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/inheritance.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2015-05-13 11:08:10 +0200
committerYves Senn <yves.senn@gmail.com>2015-05-13 11:08:10 +0200
commit15354b6fd0e73a321b695ac3961eac8df9d6125d (patch)
treee7965a8841a18cc706e8a8b7e207f377acf7f690 /activerecord/lib/active_record/inheritance.rb
parent6eaa5b17a094e5cbbdedad578e8bb2f5ae187aac (diff)
parentcbd66b430b6553e468bcdaa94af661a2d8b69d81 (diff)
downloadrails-15354b6fd0e73a321b695ac3961eac8df9d6125d.tar.gz
rails-15354b6fd0e73a321b695ac3961eac8df9d6125d.tar.bz2
rails-15354b6fd0e73a321b695ac3961eac8df9d6125d.zip
Merge branch 'sti-subclass-from-attributes' of https://github.com/agrobbin/rails into agrobbin-sti-subclass-from-attributes
Conflicts: activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/lib/active_record/inheritance.rb')
-rw-r--r--activerecord/lib/active_record/inheritance.rb14
1 files changed, 8 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/inheritance.rb b/activerecord/lib/active_record/inheritance.rb
index 24098f72dc..a7801963e8 100644
--- a/activerecord/lib/active_record/inheritance.rb
+++ b/activerecord/lib/active_record/inheritance.rb
@@ -198,14 +198,16 @@ module ActiveRecord
def subclass_from_attributes(attrs)
subclass_name = attrs.with_indifferent_access[inheritance_column]
- if subclass_name.present? && subclass_name != self.name
- subclass = subclass_name.safe_constantize
+ if subclass_name.present?
+ subclass = find_sti_class(subclass_name)
- unless descendants.include?(subclass)
- raise ActiveRecord::SubclassNotFound.new("Invalid single-table inheritance type: #{subclass_name} is not a subclass of #{name}")
- end
+ 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
+ subclass
+ end
end
end
end