# Many-to-many with extra fields

**URL:** <https://www.ruby-forum.com/t/many-to-many-with-extra-fields/52680>\
**Category:** Rails\
**Created:** [January 17, 2006, 11:08pm UTC](https://www.ruby-forum.com/t/many-to-many-with-extra-fields/52680 "2006-01-17T23:08:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kylemathews](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/51bf81/32.png) [@kylemathews](https://www.ruby-forum.com/u/kylemathews)\
**Post date:** [January 17, 2006, 11:08pm UTC](https://www.ruby-forum.com/t/many-to-many-with-extra-fields/52680/1 "2006-01-17T23:08:52Z")

</div>

I’m trying to work with a many-to-many relationship, but the join  
table needs to have a is\_primary field. What is the best way to work  
with this (adding / changing primary / deleting)? I understand that  
the :through option in Edge Rails can handle this better, but I was  
just wondering if there was a good way to handle this with Rails 1.0.

Thanks,  
Kyle

---

<div class="post-metadata">

**Author:** ![kylemathews](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/51bf81/32.png) [@kylemathews](https://www.ruby-forum.com/u/kylemathews)\
**Post date:** [January 17, 2006, 11:11pm UTC](https://www.ruby-forum.com/t/many-to-many-with-extra-fields/52680/2 "2006-01-17T23:11:53Z")

</div>

On Tue, Jan 17, 2006 at 04:30:18PM -0500, Kyle M. wrote:

> I’m trying to work with a many-to-many relationship, but the join  
> table needs to have a is\_primary field. What is the best way to work  
> with this (adding / changing primary / deleting)? I understand that  
> the :through option in Edge Rails can handle this better, but I was  
> just wondering if there was a good way to handle this with Rails 1.0.

You can create two has\_many relationships and an intermediary join  
model:  
[http://vernix.org/marcel/2has\_many.rb.txt](http://vernix.org/marcel/2has_many.rb.txt)

In the example above, you have a full join model in the Subscription  
class.

marcel
