自定义外键更改后的rails迁移

时间:2014-06-05 14:01:15

标签: ruby-on-rails foreign-keys migration

我有这个我无法弄清楚的问题。

我有两张桌子:

class NotificationTemplate < ActiveRecord::Base
  has_many :sent_notifications
end

class SentNotification < ActiveRecord::Base
  belongs_to :notification_template
end

没有属于表格的这一行:

belongs_to :notification_template, foreign_key: "template_id"

困难的部分是NotificationTemplate有翻译表,它存储以前的外键。有没有办法改变这两个外键。因为我无法通过ActiveRecord访问该转换表。

修改

我创建了这2个模型,并在没有foreign_key: "template_id"的情况下运行了迁移,生成了默认foreign_key的导轨,notification_template_id。这对我来说太长了。所以现在我在模型中更改了外键,需要创建一个迁移,它将更改此关联的所有表外键。有没有某种方法可以做到这一点,没有rename_column迁移所有关联?

0 个答案:

没有答案
相关问题