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
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to