I would like to select a user's groups where the join table is marked with
favorit: true
User
Groups
UsersGroup
UsersGroup
group_id
user_id
favorit
current_user.groups.joins(:users_group).where(:users_group => { :favorit => true })
current_user.groups.where(users_group.favorit == true)
You can use:
current_user.user_groups.where(favorit: true)
If you want to access the groups from this, you can get the group
from the user_groups
found above. I.E.
favorits = current_user.user_groups.where(favorit: true).includes(:group)
favorits.map(&:group)
Notice the includes
in there to eager load the groups and avoid any N + 1 issues.
Does that do what you're looking for?