Method: ActiveRecord::ModelSchema::ClassMethods#reset_column_information
- Defined in:
- lib/active_record/model_schema.rb
#reset_column_information ⇒ Object
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, e.g.:
class CreateJobLevels < ActiveRecord::Migration[8.1]
def up
create_table :job_levels do |t|
t.integer :id
t.string :name
t.
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
539 540 541 542 543 544 545 546 |
# File 'lib/active_record/model_schema.rb', line 539 def reset_column_information connection_pool.active_connection&.clear_cache! ([self] + descendants).each(&:undefine_attribute_methods) schema_cache.clear_data_source_cache!(table_name) reload_schema_from_cache initialize_find_by_cache end |