How do I force ActiveRecord to reload a class?

后端 未结 3 443
轻奢々
轻奢々 2021-01-31 07:25

I\'m creating a bunch of migrations, some of which are standard \"create table\" or \"modify table\" migrations, and some of which modify data. I\'m using my actual ActiveRecor

3条回答
  •  抹茶落季
    2021-01-31 07:42

    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.title
    end
    

提交回复
热议问题