【发布时间】:2010-01-30 06:36:31
【问题描述】:
我的 Rails 应用程序中有一个模型,它使用has_one 的:class_name 属性:
class Foo < ActiveRecord:Base
has_one :main_bar, :class_name => "Bar"
# ...
end
我现在有点不确定要在这个类的迁移中添加什么。我可以使用参考吗? Rails 将寻找什么作为:main_bar 的列名?我可以这样吗?
class CreateFoos < ActiveRecord::Migration
def self.up
create_table :foos do |t|
t.references :main_bar
end
end
def self.down
drop_table :foos
end
end
谢谢!
【问题讨论】:
标签: ruby-on-rails migration reference has-one