Forum: Ruby on Rails Replacing a "has many through" collection

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Morten (Guest)
on 2007-07-12 14:45
(Received via mailing list)
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.users << my_new_users

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


This topic is locked and can not be replied to.