Skip to content
This repository
Browse code

Optimize instantiation of STI subclass records. In partial fullfilmen…

…t of #1236.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2511 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit eb2fbf05c6a0f367bc330618076b99dd5a8bf308 1 parent f4d1af3
Marcel Molina authored
2  activerecord/CHANGELOG
... ... @@ -1,5 +1,7 @@
1 1 *SVN*
2 2
  3 +* Optimize instantiation of STI subclass records. In partial fullfilment of #1236. [skaes@web.de]
  4 +
3 5 * Fix typo of 'constrains' to 'contraints'. #2069. [Michael Schuerig <michael@schuerig.de>]
4 6
5 7 * Optimization refactoring for add_limit_offset!. In partial fullfilment of #1236. [skaes@web.de]
33 activerecord/lib/active_record/base.rb
@@ -782,22 +782,25 @@ def ===(object)
782 782 # Finder methods must instantiate through this method to work with the single-table inheritance model
783 783 # that makes it possible to create objects of different types from the same table.
784 784 def instantiate(record)
785   - subclass_name = record[inheritance_column]
786   - require_association_class(subclass_name)
787   -
788   - object = if subclass_name.blank?
789   - allocate
790   - else
791   - begin
792   - compute_type(subclass_name).allocate
793   - rescue NameError
794   - raise SubclassNotFound,
795   - "The single-table inheritance mechanism failed to locate the subclass: '#{record[inheritance_column]}'. " +
796   - "This error is raised because the column '#{inheritance_column}' is reserved for storing the class in case of inheritance. " +
797   - "Please rename this column if you didn't intend it to be used for storing the inheritance class " +
798   - "or overwrite #{self.to_s}.inheritance_column to use another column for that information."
  785 + object =
  786 + if subclass_name = record[inheritance_column]
  787 + if subclass_name.empty?
  788 + allocate
  789 + else
  790 + require_association_class(subclass_name)
  791 + begin
  792 + compute_type(subclass_name).allocate
  793 + rescue NameError
  794 + raise SubclassNotFound,
  795 + "The single-table inheritance mechanism failed to locate the subclass: '#{record[inheritance_column]}'. " +
  796 + "This error is raised because the column '#{inheritance_column}' is reserved for storing the class in case of inheritance. " +
  797 + "Please rename this column if you didn't intend it to be used for storing the inheritance class " +
  798 + "or overwrite #{self.to_s}.inheritance_column to use another column for that information."
  799 + end
  800 + end
  801 + else
  802 + allocate
799 803 end
800   - end
801 804
802 805 object.instance_variable_set("@attributes", record)
803 806 object

0 comments on commit eb2fbf0

Please sign in to comment.
Something went wrong with that request. Please try again.