Answer the question
In order to leave comments, you need to log in
How to make two foreign keys in one table?
Ruby on Rails
has two tables:
Users:
id
name
Orders:
id
buyer
seller
Answer the question
In order to leave comments, you need to log in
Examples for the answer nbekseitov
class Buyer < User
end
class Seller < User
end
class Order
belongs_to :buyer
belongs_to :seller
end
class Order
belongs_to :buyer, foreign_key: :buyer_id, class_name: User
belongs_to :seller, foreign_key: :seller_id, class_name: User
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question