我的情况是这样的。公司有很多用户,用户可能属于很多公司。当前的实现如下所示。
class Company
has_many :employments
has_many :users, :through => :employments
end
class Employment
belongs_to :company
belongs_to :user
end
class User
has_many :employments
has_many :companies, :through => :employments #This doesn't looks correct
end
它有效,但“用户拥有许多公司”在逻辑上看起来没有意义。它一定是类似belongs_to_many 公司的东西。我需要使用 has_and_belongs_to_many 吗?
有人可以建议代表这些关系的正确方法吗?