【发布时间】:2017-08-15 17:06:28
【问题描述】:
所以我有两个表,一个客户表和一个公司表。我还创建了一个空的员工表,我想将其用作连接表。
这些是我拥有的关联:(我希望客户与他们各自的公司相关联)
class Company < ApplicationRecord
has_many :employees
has_many :customers, :through => :employees
end
class Customer < ApplicationRecord
belongs_to :employees
end
class Employee < ApplicationRecord
belongs_to :customer
belongs_to :company
end
哪里是最好的方法?在控制器中的我的 Customer#new 方法中?我读到我需要使用
【问题讨论】:
-
一个
customer属于还是有很多employees?employee是否属于或拥有一个customer?现在你有belongs_to双向
标签: ruby-on-rails postgresql jointable