這裏是客戶:如何添加一列以引用RoR上的另一個表?
class CreateCustomer < ActiveRecord::Migration
def self.up
create_table :customers do |t|
t.column :email, :string, :null => false
end
end
def self.down
drop_table :customers
end
end
這是客戶信息:
class CustomerInfo < ActiveRecord::Migration
def self.up
create_table :statuses do |t|
t.column :statuses, :string, :null => false
end
end
def self.down
drop_table :status
end
end
我想要做的是客戶和客戶信息有一一對應的關係。我如何在新遷移中完成此操作?謝謝。
因此,我不需要在我的遷移中添加額外的代碼?只要去模型,並設置has_one和belongs_to關係,所有的魔法將起作用? – Tattat 2010-07-11 07:40:47
你需要在遷移中添加外鍵(customer_id),但在此之後,是的,只是has_one/belongs_to是它 – x1a4 2010-07-11 07:46:12