# Manipulating has\_many :through associations

**URL:** <https://www.ruby-forum.com/t/manipulating-has-many-through-associations/93576>\
**Category:** Rails\
**Created:** [April 4, 2006, 9:57pm UTC](https://www.ruby-forum.com/t/manipulating-has-many-through-associations/93576 "2006-04-04T21:57:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bradley\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7ba0ec/32.png) [@Bradley\_M](https://www.ruby-forum.com/u/Bradley_M)\
**Post date:** [April 4, 2006, 9:57pm UTC](https://www.ruby-forum.com/t/manipulating-has-many-through-associations/93576/1 "2006-04-04T21:57:29Z")

</div>

Hi,

I haven’t done any associations before, so please forgive my incorrect  
use of terminology…

If I set up a has\_many :through association, can I manipulate the  
associated instances directly (like an Array), or do I need to  
manipulate the join model?

For example, suppose I have two classes and the associated join model:

class foo  
has\_many :foo\_bars  
has\_many :bars, :through =\> :foo\_bars

class bar  
has\_many :foo\_bars  
has\_many :foos, :through =\> :foo\_bars

class foo\_bars  
belongs\_to :foo  
belongs\_to :bar

If I have an instance of foo and an instance of bar, how do I add the  
association between the two of them?

my\_foo.bars \<\< my\_bar

or (inversely),

my\_bar.foos \<\< my\_foo

or do I somehow need to manipulate the join model explicitly?

## Thanks, Brad

Bradley M.

---

<div class="post-metadata">

**Author:** ![Bradley\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7ba0ec/32.png) [@Bradley\_M](https://www.ruby-forum.com/u/Bradley_M)\
**Post date:** [April 4, 2006, 10:25pm UTC](https://www.ruby-forum.com/t/manipulating-has-many-through-associations/93576/2 "2006-04-04T22:25:07Z")

</div>

I think my\_foo.foo\_bars.create(:bars =\> my\_bar) would work. Am not sure  
if  
that is the best way to do it though.
