# Replacing a "has many through" collection

**URL:** <https://www.ruby-forum.com/t/replacing-a-has-many-through-collection/109208>\
**Category:** Rails\
**Created:** [July 12, 2007, 12:45pm UTC](https://www.ruby-forum.com/t/replacing-a-has-many-through-collection/109208 "2007-07-12T12:45:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![morten](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/cdc98d/32.png) [@morten](https://www.ruby-forum.com/u/morten)\
**Post date:** [July 12, 2007, 12:45pm UTC](https://www.ruby-forum.com/t/replacing-a-has-many-through-collection/109208/1 "2007-07-12T12:45:55Z")

</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
