当前位置:网站首页>How to force activerecord to reload a class- How do I force ActiveRecord to reload a class?

How to force activerecord to reload a class- How do I force ActiveRecord to reload a class?

2022-07-05 04:17:00 French red wine sweet

problem :

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 am creating a series of migrations , Some of them are standard “ Create table ” or “ Modify table ” transfer , Some of these migrations modify data .I'm using my actual ActiveRecord models to modify the data, a la: I am using my actual ActiveRecord Model to modify data ,a:

Blog.all.each do |blog|  update_some_blog_attributes_to_match_new_schemaend

The problem is that if I load the Blog class, then modify the table, then use the Blog class again, the models have the old table definitions, and cannot save to the new table. The problem is , If I load Blog class , Then modify the table , Then use it again Blog class , Model has old table definition , And cannot be saved to a new table .Is there a way to reload the classes and their attribute definitions so I can reuse them? Is there any way to reload classes and their attribute definitions , So that I can reuse them ?


Solution :

Reference resources : https://stackoom.com/en/question/qEv
原网站

版权声明
本文为[French red wine sweet]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140650088923.html