我創建了一堆遷移,其中一些標準的「創建表」或「修改表」遷移,其中一些修改數據。我用我的實際ActiveRecord的模型修改數據,一拉:如何強制ActiveRecord重新加載課程?
Blog.all.each do |blog|
update_some_blog_attributes_to_match_new_schema
end
的問題是,如果我加載博客類,然後修改表,然後再使用博客類,模特有舊的表定義,並且不能保存到新的表中。有沒有辦法重新加載類和它們的屬性定義,所以我可以重用它們?
小心有關係的模型。如果`class Blog; belongs_to所有者; end`,那麼除了Blog之外,您可能還需要`Owner.reset_column_information`。 – 2012-06-05 05:33:11