diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-11 15:16:09 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-11 15:16:09 -0800 |
commit | 8c71e8b18f0e589b5413a8e6b6d7336a5506c977 (patch) | |
tree | a64cc15c7ec1f18ddff7f739355d2838c303d82b /activerecord/lib/active_record/base.rb | |
parent | af96018c9171a9021f915ec63bd0baf4cf5a8e39 (diff) | |
download | rails-8c71e8b18f0e589b5413a8e6b6d7336a5506c977.tar.gz rails-8c71e8b18f0e589b5413a8e6b6d7336a5506c977.tar.bz2 rails-8c71e8b18f0e589b5413a8e6b6d7336a5506c977.zip |
lazily instantiate AR objects in order to avoid NoMethodErrors
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rw-r--r-- | activerecord/lib/active_record/base.rb | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 1079094bbf..a5b71ba280 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -880,6 +880,16 @@ module ActiveRecord #:nodoc: record end + + # 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) # :nodoc: + model = find_sti_class(record[inheritance_column]).allocate + model.init_with('attributes' => record) + model + end + private def relation #:nodoc: @@ -892,15 +902,6 @@ module ActiveRecord #:nodoc: end end - # 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) - model = find_sti_class(record[inheritance_column]).allocate - model.init_with('attributes' => record) - model - end - def find_sti_class(type_name) if type_name.blank? || !columns_hash.include?(inheritance_column) self |