diff options
-rw-r--r-- | activerecord/lib/active_record/base.rb | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 5da4eb169b..e86d4984a6 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -884,21 +884,13 @@ module ActiveRecord #:nodoc: # single-table inheritance model that makes it possible to create # objects of different types from the same table. def instantiate(record) - object = find_sti_class(record[inheritance_column]).allocate - - object.instance_variable_set(:@attributes, record) - object.instance_variable_set(:@attributes_cache, {}) - object.instance_variable_set(:@new_record, false) - object.instance_variable_set(:@readonly, false) - object.instance_variable_set(:@destroyed, false) - object.instance_variable_set(:@marked_for_destruction, false) - object.instance_variable_set(:@previously_changed, {}) - object.instance_variable_set(:@changed_attributes, {}) - - object.send(:_run_find_callbacks) - object.send(:_run_initialize_callbacks) - - object + find_sti_class(record[inheritance_column]).allocate.instance_eval do + @attributes, @attributes_cache, @previously_changed, @changed_attributes = record, {}, {}, {} + @new_record = @readonly = @destroyed = @marked_for_destruction = false + _run_find_callbacks + _run_initialize_callbacks + self + end end def find_sti_class(type_name) |