Replacing a "has many through" collection


#1

Hi, given a data model like this:

membership belongs_to user
membership belongs_go group

user has_many memberships
user has_many groups through memberships

group has_many memberships
group has_many users through memberships

What’s the most elegant way of setting a new collection of users as
members in a group? Anything better than:

group.memberships.clear
group.users << my_new_users

In a normal has_many relationship, you can do group.users =
my_new_users, but that doesn’t “go through”.

Br.

Morten