How do I force ActiveRecord to reload a class? How do I force ActiveRecord to reload a class? ruby ruby

How do I force ActiveRecord to reload a class?


The answer is yes!

Blog.reset_column_information


I always used new models in migrations

    MyBlog < ActiveRecord::Base      set_table_name 'blogs'    end    def self.up      MyBlog.all.each do |blog|        update_some_blog_attributes_to_match_new_schema      end    end

But Blog.reset_column_information is more convenient.


Create new instances:


Old_blogs = Blog.all

# change/modify db table in here

New_blogs = Blog.all # this should be reloaded or you could use the .reload on this

# change information, load old into new

ex.

Old_blogs.each do |blog|  New_blogs.find(blog.id).title = blog.titleend