# Q on P331 in SimpleRails2 book

**URL:** <https://www.ruby-forum.com/t/q-on-p331-in-simplerails2-book/190991>\
**Category:** Rails\
**Created:** [July 2, 2010, 1:00am UTC](https://www.ruby-forum.com/t/q-on-p331-in-simplerails2-book/190991 "2010-07-02T01:00:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![railsfan\_radha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/41988e/32.png) [@railsfan\_radha](https://www.ruby-forum.com/u/railsfan_radha)\
**Post date:** [July 2, 2010, 1:00am UTC](https://www.ruby-forum.com/t/q-on-p331-in-simplerails2-book/190991/1 "2010-07-02T01:00:42Z")

</div>

If anyone has read the book,  
Sitepoint "Simply Rails 2 " book.  
then…  
here is my mind breaking q:

## Page 331

Join Model Relationship:  
He has User Model, Story Model and Votes Model in the sample scenario  
which he is walking through in this book.  
User can write many stories. So, User :has\_many relationships to  
Storries.  
USer can vote to many stories. So, User :has\_many Votes to Stories.  
Vote :belongs\_to Stories

What I don’t get is:

Why should he add this join model Relationship?  
I understand he is trying to explain the different relationships, etc.  
etc.  
But, in this case, what would it lack, if the Join Model relationship is  
not set in the User Model ? (Atleast in this case)

## Here is the excerpt from the book: Page 331:

Introducing the has\_many :through Association  
The code that implements a join model relationship is the line has\_many  
:through. Letâ€™s use it to add a join model relationship to our User  
model. Open the file app/models/user.rb and make the changes in bold  
below:  
22-user  
.rb  
(excerpt)  
class User \< ActiveRecord::Base  
has\_many :stories  
has\_many :votes  
has\_many :stories\_voted\_on,  
:through =\> :votes,  
:source =\> :story  
end  
Normally, Rails is smart enough to figure out associated class names on  
its own, so long as the associations are given a name that matches the  
plural form of the class name (for instance, :stories). However, because  
our User model already has a has\_manyrelationship (has\_many :stories),  
we need to assign this new association a different name  
(:stories\_voted\_on). We also need to specify the model with which weâ€™re  
associating the users, which is exactly what the :source =\> :story  
argument does.

* * *

If any is not clear, please let me know.

- thanks,  
radha
