2017-09-21 14 views

答えて

0

これを試してみてください ...

class User < ApplicationRecord 
    has_many :memberships 
    has_many :groups, through: :memberships 
end 
class Group < ApplicationRecord 
    has_many :memberships 
    has_many :groups, through: :memberships 
end 
class Membership < ApplicationRecord 
    belongs_to :user 
    belongs_to :group 
end 

has_manyの削除:ユーザーとhas_manyの:グループメンバシップテーブルを介してユーザーグループまたはグループのユーザーにアクセスするように...

User.find(1).groups 
また

か...

Group.find(1).users 

、間違いなく読み答えに記載されている文献https://stackoverflow.com/a/46350230/8503822

関連する問題