Simple Association Help

Oh to the glory of reading books :slight_smile: 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

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)

Do it like this: belongs_to :article belongs_to :user

They can not share a line.