Rails has_many&自我指涉协会| has_many中的foreign_key应该是什么?

时间:2016-06-05 19:39:33

标签: ruby-on-rails associations has-many self-reference

我有预订模式和用户模型。

class Booking < ActiveRecord::Base
  belongs_to :buyer, class_name: "User"
  belongs_to :seller, class_name: "User"
end

这是我的User.rb

class User < ActiveRecord::Base
 has_many :bookings, foreign_key: "WHAT_SHOULD_I_GIVE_HERE", dependent: :destroy
end

在User.rb中,我怎么能提到&#39; seller_id&#39;和&#39; buyer_id&#39;是foreign_keys吗?

0 个答案:

没有答案