diff options
author | Marcel Molina <marcel@vernix.org> | 2005-10-09 22:26:54 +0000 |
---|---|---|
committer | Marcel Molina <marcel@vernix.org> | 2005-10-09 22:26:54 +0000 |
commit | eb2fbf05c6a0f367bc330618076b99dd5a8bf308 (patch) | |
tree | 03a0c2572a59baded91035e737c79029f485817e /activerecord | |
parent | f4d1af3085cbe95cd8363fae86696a723122c195 (diff) | |
download | rails-eb2fbf05c6a0f367bc330618076b99dd5a8bf308.tar.gz rails-eb2fbf05c6a0f367bc330618076b99dd5a8bf308.tar.bz2 rails-eb2fbf05c6a0f367bc330618076b99dd5a8bf308.zip |
Optimize instantiation of STI subclass records. In partial fullfilment of #1236.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2511 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 33 |
2 files changed, 20 insertions, 15 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index a5cafb69f9..6557e76a66 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Optimize instantiation of STI subclass records. In partial fullfilment of #1236. [skaes@web.de] + * Fix typo of 'constrains' to 'contraints'. #2069. [Michael Schuerig <michael@schuerig.de>] * Optimization refactoring for add_limit_offset!. In partial fullfilment of #1236. [skaes@web.de] diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 022b577704..5e61d26b79 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -782,22 +782,25 @@ module ActiveRecord #:nodoc: # Finder methods must instantiate through this method to work with the single-table inheritance model # that makes it possible to create objects of different types from the same table. def instantiate(record) - subclass_name = record[inheritance_column] - require_association_class(subclass_name) - - object = if subclass_name.blank? - allocate - else - begin - compute_type(subclass_name).allocate - rescue NameError - raise SubclassNotFound, - "The single-table inheritance mechanism failed to locate the subclass: '#{record[inheritance_column]}'. " + - "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 #{self.to_s}.inheritance_column to use another column for that information." + object = + if subclass_name = record[inheritance_column] + if subclass_name.empty? + allocate + else + require_association_class(subclass_name) + begin + compute_type(subclass_name).allocate + rescue NameError + raise SubclassNotFound, + "The single-table inheritance mechanism failed to locate the subclass: '#{record[inheritance_column]}'. " + + "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 #{self.to_s}.inheritance_column to use another column for that information." + end + end + else + allocate end - end object.instance_variable_set("@attributes", record) object |