From 6941c98ec93a0f7427e54c40ce3a3309d04d61ca Mon Sep 17 00:00:00 2001 From: "Hongli Lai (Phusion)" Date: Wed, 17 Sep 2008 02:53:39 +0200 Subject: Improve documentation for ActiveRecord::Base#reset_column_information --- activerecord/lib/active_record/base.rb | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 91b69747e0..a925ba6e20 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1221,7 +1221,32 @@ module ActiveRecord #:nodoc: end end - # Resets all the cached information about columns, which will cause them to be reloaded on the next request. + # Resets all the cached information about columns, which will cause them + # to be reloaded on the next request. + # + # The most common usage pattern for this method is probably in a migration, + # when just after creating a table you want to populate it with some default + # values, eg: + # + # class CreateJobLevels < ActiveRecord::Migration + # def self.up + # create_table :job_levels do |t| + # t.integer :id + # t.string :name + # + # t.timestamps + # end + # + # JobLevel.reset_column_information + # %w{assistant executive manager director}.each do |type| + # JobLevel.create(:name => type) + # end + # end + # + # def self.down + # drop_table :job_levels + # end + # end def reset_column_information generated_methods.each { |name| undef_method(name) } @column_names = @columns = @columns_hash = @content_columns = @dynamic_methods_hash = @generated_methods = @inheritance_column = nil -- cgit v1.2.3