class method self.reset_column_information

Ruby on Rails 3.1.12

Since v2.2.3 Last seen in v3.1.12

Available in: v2.2.3 v2.3.18 v3.0.20 v3.1.12

Signature

self.reset_column_information()

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 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 down
    drop_table :job_levels
  end
end
Source
# File activerecord/lib/active_record/base.rb, line 777
      def reset_column_information
        connection.clear_cache!
        undefine_attribute_methods
        connection_pool.clear_table_cache!(table_name) if table_exists?

        @column_names = @content_columns = @dynamic_methods_hash = @inheritance_column = nil
        @arel_engine = @relation = nil
      end

Defined in activerecord/lib/active_record/base.rb line 777 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::Base

Type at least 2 characters to search.

↑↓ navigate · open · esc close