# Replacing a "has many through" collection

**URL:** <https://discuss.rubyonrails.org/t/replacing-a-has-many-through-collection/15564>\
**Category:** rubyonrails-talk\
**Created:** [July 12, 2007, 10:45am UTC](https://discuss.rubyonrails.org/t/replacing-a-has-many-through-collection/15564 "2007-07-12T10:45:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Morten](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@Morten](https://discuss.rubyonrails.org/u/Morten)\
**Post date:** [July 12, 2007, 10:45am UTC](https://discuss.rubyonrails.org/t/replacing-a-has-many-through-collection/15564/1 "2007-07-12T10:45:10Z")

</div>

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
