# Storing additional data on join tables with Rails

**URL:** <https://www.ruby-forum.com/t/storing-additional-data-on-join-tables-with-rails/59795>\
**Category:** Rails\
**Created:** [May 6, 2006, 7:19pm UTC](https://www.ruby-forum.com/t/storing-additional-data-on-join-tables-with-rails/59795 "2006-05-06T19:19:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a4c791/32.png) [@alder](https://www.ruby-forum.com/u/alder)\
**Post date:** [May 6, 2006, 7:19pm UTC](https://www.ruby-forum.com/t/storing-additional-data-on-join-tables-with-rails/59795/1 "2006-05-06T19:19:45Z")

</div>

Hi there

I need to store additional attributes on join table. Searching the  
Wiki [1] revealed two possible methods:

1. push\_with\_attributes, as described by Justin Palmer [2].  
Unfortunately, “this method is now deprecated” [3]. Even if it wasn’t,  
there seem to be inherent problems with that approach, for example  
with updating those additional attributes, though Joshua M. have  
provided us with a plugin for that [4].

2. promote the join-table to a full module. This approach seems to  
integrate better with Rails, and even a newb like me can sense that it  
has a lesser chance of rubbing ActiveRecord’s magic the wrong way,  
thereby breaking something. Still, that habtm association is just an  
association, not a model. I wouldn’t want to make it a model if I  
could help it.

So, what’s the best practice for storing additional data on join  
tables with Rails?

-Alder

* * *

[1] [Peak Obsession](http://wiki.rubyonrails.com/rails/pages/has_and_belongs_to_many)  
[2]  
[http://encytemedia.com/blog/articles/2005/06/15/storing-additional-data-on-join-tables-with-rails#comment-490](http://encytemedia.com/blog/articles/2005/06/15/storing-additional-data-on-join-tables-with-rails#comment-490)  
[3]  
[Peak Obsession](http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html)  
[4]  
[Peak Obsession](http://wiki.rubyonrails.com/rails/pages/Update+has_and_belongs_to_many+Attributes)

---

<div class="post-metadata">

**Author:** ![alder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a4c791/32.png) [@alder](https://www.ruby-forum.com/u/alder)\
**Post date:** [May 6, 2006, 7:23pm UTC](https://www.ruby-forum.com/t/storing-additional-data-on-join-tables-with-rails/59795/2 "2006-05-06T19:23:05Z")

</div>

Make the join table a full model and look in the docs for has\_many  
:through

> **[ActiveRecord::Associations::ClassMethods](https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html)**
>
> Associations are a set of macro-like class methods for tying objects together through foreign keys.

Peter

---

<div class="post-metadata">

**Author:** ![alder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a4c791/32.png) [@alder](https://www.ruby-forum.com/u/alder)\
**Post date:** [May 6, 2006, 7:54pm UTC](https://www.ruby-forum.com/t/storing-additional-data-on-join-tables-with-rails/59795/3 "2006-05-06T19:54:53Z")

</div>

Alder G. wrote:

> So, what’s the best practice for storing additional data on join  
> tables with Rails?

[http://blog.hasmanythrough.com/articles/2006/04/20/many-to-many-dance-off](http://blog.hasmanythrough.com/articles/2006/04/20/many-to-many-dance-off)

–  
Josh S.  
[http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

---

<div class="post-metadata">

**Author:** ![alder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a4c791/32.png) [@alder](https://www.ruby-forum.com/u/alder)\
**Post date:** [May 6, 2006, 9:10pm UTC](https://www.ruby-forum.com/t/storing-additional-data-on-join-tables-with-rails/59795/4 "2006-05-06T21:10:03Z")

</div>

On 5/6/06, Josh S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Alder G. wrote:
> 
> > So, what’s the best practice for storing additional data on join  
> > tables with Rails?
> 
> [http://blog.hasmanythrough.com/articles/2006/04/20/many-to-many-dance-off](http://blog.hasmanythrough.com/articles/2006/04/20/many-to-many-dance-off)
> 
> –  
> Josh S.  
> [http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

Thanks Josh!

“has\_many :through” is awesome, and your article is very informative.

Certainly, through associations are the proper way to do what I want.

Regards,  
Alder
