我有三种模式 - Company
,User
和CompanyUser
。这些协会如下。模特协会 - has_many:通过
Company.rb
has_many :company_users
has_many :users, :through => :company_users
User.rb
has_many :company_users, :dependent => :destroy
belongs_to :company
CompanyUser.rb
belongs_to :company
belongs_to :user
有关读取current_user.company,在模型关联进行什么moddifications ?
任何帮助,将不胜感激。
可以请你写你在使用轨控制台上current_user.company得到的输出? – power
你不能把你的'FK'放在用户模型中,所以把'belongs_to:company'替换成'hash_many:companies,:through =>:company_users' –