Kim
(Kim)
January 27, 2007, 12:47am
1
Oh to the glory of reading books
I think you want a one-to-many relationship, if so, this is what you
need:
Article model:
belongs_to :user
Comment model:
belongs_to :user
User model:
has_many :article
has_many :comment
Straight frome *the* book (Agile Web Development with Rails)
"There's an important rule illustrated here: the model for the table
that contains
the foreign key always has the belongs_to declaration."
Therefor Article and Comments must have a column called user_id
Hope that helps -K
jamiequint
(jamiequint@gmail.com)
January 27, 2007, 1:06am
2
I believe that would be....
Article model:
belongs_to :user
Comment model:
belongs_to :user
User model:
has_many :articles
has_many :comments
also, you must remember to create the foreign keys in your database. In
this case they would go in the Comment and User tables in the database.
(you need a user_id column in these tables for the association to work)
Kim
(Kim)
February 8, 2007, 11:45pm
3
Do it like this:
belongs_to :article
belongs_to :user
They can not share a line.