Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improve documentation for ActiveRecord::Base#reset_column_information

  • Loading branch information...
commit 6941c98ec93a0f7427e54c40ce3a3309d04d61ca 1 parent 606b62a
@FooBarWidget FooBarWidget authored
Showing with 26 additions and 1 deletion.
  1. +26 −1 activerecord/lib/active_record/base.rb
View
27 activerecord/lib/active_record/base.rb
@@ -1221,7 +1221,32 @@ def column_methods_hash #: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
Please sign in to comment.
Something went wrong with that request. Please try again.