You have to create the following migration:
rails g migration AddBuyerAndSellerToSales buyer:references seller:references
This should create the following migration file:
class AddBuyerAndSellerToSales < ActiveRecord::Migration
def change
add_reference :sales, :buyer, index: true, foreign_key: true
add_reference :sales, :seller, index: true, foreign_key: true
end
end
If you use a database engine like PostgreSQL you have to tell the engine to which table the foreign key will point.
class AddBuyerAndSellerToSales < ActiveRecord::Migration
def change
add_reference :sales, :buyer, index: true # foreign_key: true <= remove this!
add_reference :sales, :seller, index: true # foreign_key: true <= remove this!
add_foreign_key :sales, :users, column: :buyer_id
add_foreign_key :sales, :users, column: :seller_id
end
end
Hope this helps!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…