【发布时间】:2011-07-24 06:04:34
【问题描述】:
我想将我目前拥有的belongs_to 关系迁移到has_and_belongs_to_many 关系。理想情况下,我希望在我构建的迁移中执行此操作。
当我添加这个作为这两个项目的连接 ID 的新迁移时,我可以随后更改该迁移中的模型吗?
#migration code goes here to add the new item field
Item.find(:all).each do |item|
specific changes to item to account for the new relationship
end
或者这不是我在那个 rake 环境中可以做的事情吗?我想将对象迁移到使用新的 HABTM 系统,我是否必须在实际代码本身中检查它并在启动应用程序实例之前将其作为单独的 rake 任务运行?
【问题讨论】:
标签: ruby-on-rails migration relationship