I have three models:
User
class User < ApplicationRecord has_many :memberships has_many :parties, through: :memberships end
Membership
class Membership < ApplicationRecord belongs_to :user belongs_to :party end
Party
class Party < ApplicationRecord has_many :memberships has_many :users, through: :memberships end
Everything seems to work. Users can be in several groups and in one group several users.
I added the Role field to Membership . It turns out that users can have different roles in different groups. I have a party object, from it I calmly get the desired user , how to get its role correctly? I am writing something like:
m = user.memberships.find_by party_id: @party.id role = m.role
I think this is wrong, tell me, please. Maybe there are fundamental fundamental errors?