# Need help on Many to Many Relationships

**URL:** <https://www.ruby-forum.com/t/need-help-on-many-to-many-relationships/175407>\
**Category:** Rails\
**Created:** [September 13, 2009, 1:10am UTC](https://www.ruby-forum.com/t/need-help-on-many-to-many-relationships/175407 "2009-09-13T01:10:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MS999](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9d8465/32.png) [@MS999](https://www.ruby-forum.com/u/MS999)\
**Post date:** [September 13, 2009, 1:10am UTC](https://www.ruby-forum.com/t/need-help-on-many-to-many-relationships/175407/1 "2009-09-13T01:10:22Z")

</div>

Hi,  
Does anyone know where I can find a full step by step tutorial on Many  
to Many Relationships with Rails or can describe the steps in  
inserting data into the join tables, displaying the connections, etc…

- I don’t only need the model, but all the steps that you would use in  
the MVC architecture to make it work.

I am a new to Rails and I cannot find a complete tutorial on all the  
steps needed to make this work probably. I have tried a number of  
different things, but a lot of the tutorials online are from 2 years  
ago and a lot has changed since then.

What I am trying to do is a CRUD system that works with Many to Many  
relationships.

Example:  
There will be 2 objects - books and authors  
authors has many books  
books has many authors (say more then 1 author wrote the book)

I then want to display a list of books and one of the fields I will be  
pulling from the database is the authors associated with the books.

Then the same with authors.

I want to be able to insert, update, edit, delete from the ruby on  
rails application, not manually from the Mysql database.

Thank you

---

<div class="post-metadata">

**Author:** ![MS999](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9d8465/32.png) [@MS999](https://www.ruby-forum.com/u/MS999)\
**Post date:** [September 13, 2009, 5:23pm UTC](https://www.ruby-forum.com/t/need-help-on-many-to-many-relationships/175407/2 "2009-09-13T17:23:08Z")

</div>

On Sat, Sep 12, 2009 at 6:07 PM, MS999 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,  
> Does anyone know where I can find a full step by step tutorial on Many  
> to Many Relationships with Rails or can describe the steps in  
> inserting data into the join tables, displaying the connections, etc…

I always use an actual join model and :through.

The Many-to-many section on this page explains how it works:

> **[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.

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![MS999](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9d8465/32.png) [@MS999](https://www.ruby-forum.com/u/MS999)\
**Post date:** [September 14, 2009, 12:06pm UTC](https://www.ruby-forum.com/t/need-help-on-many-to-many-relationships/175407/3 "2009-09-14T12:06:52Z")

</div>

I have given the details @

[http://www.ruby-forum.com/topic/191527](http://www.ruby-forum.com/topic/191527)

try and let me know

[Open Source Craigslist in  
Rails](http://www.craigslistcloned.com)

---

<div class="post-metadata">

**Author:** ![MS999](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9d8465/32.png) [@MS999](https://www.ruby-forum.com/u/MS999)\
**Post date:** [September 14, 2009, 1:02pm UTC](https://www.ruby-forum.com/t/need-help-on-many-to-many-relationships/175407/4 "2009-09-14T13:02:31Z")

</div>

Hi  
Read these

> **[Active Record Associations — Ruby on Rails Guides](https://guides.rubyonrails.org/association_basics.html#the-has-and-belongs-to-many-association)**
>
> Active Record AssociationsThis guide covers the association features of Active Record.After reading this guide, you will know: How to declare associations between Active Record models. How to understand the various types of Active Record...

> **[Active Record Associations — Ruby on Rails Guides](https://guides.rubyonrails.org/association_basics.html#the-has-many-through-association)**
>
> Active Record AssociationsThis guide covers the association features of Active Record.After reading this guide, you will know: How to declare associations between Active Record models. How to understand the various types of Active Record...

> **[Active Record Associations — Ruby on Rails Guides](https://guides.rubyonrails.org/association_basics.html#choosing-between-has-many-through-and-has-and-belongs-to-many)**
>
> Active Record AssociationsThis guide covers the association features of Active Record.After reading this guide, you will know: How to declare associations between Active Record models. How to understand the various types of Active Record...

Sijo
