Forum: Ruby on Rails belongs_to, has_one, has_many question (again?)

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
3948345772146ca07fe74b2bb7d5d630?d=identicon&s=25 Tom de Grunt (Guest)
on 2006-02-20 23:51
(Received via mailing list)
Hi All,

Probably this has been asked numerous times, I apologize already!
Can somebody point me to a good tutorial on how Rails works with

I know about database design and normalization, I also know about
programming in general (and OOP for that matter).

Only thing I can say is that I'm following the "Four days on Rails"
tutorial by John McCreesh.
He writes on Items and Notes (for his Todo example).

The items table has a key to the note_id. However (and this in
particular I'm trying to understand), the Models which accompany the
tables (item & note) are like:

class Item                class Note
belongs_to: note          # nothing here really
.                         .
.                         .
end                       end

It only struck me that I have the feeling that "it" (belongs_to)
should be the other way around.
I'm actually looking for some page which spills out the relations or
associations within Rails, like:

1:1 relation: has_one, belongs_to in such and such way
1:many relation has_many, belongs_to in such and such way
many:many relation: already has a tutorial of it's own! (http://

8e44c65ac5b896da534ef2440121c953?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-02-21 02:06
(Received via mailing list)
On Feb 20, 2006, at 2:49 PM, Tom de Grunt wrote:

> tutorial by John McCreesh.
> end                       end
> Thanks,
> Tom


	Here is a link with a lot of info:

	And you have it correct already, the belongs_to is a bit confusing.
It helps to think about it this way, instead of belongs to think
referrs_to or has_fkey_that_refers_to . The model that belongs_to
another model is the one that has the foriegn key so since item has a
note_id columns item belongs_to Note or Item refers_to Note.

-Ezra Zygmuntowicz
Yakima Herald-Republic Newspaper
This topic is locked and can not be replied to.