Assuming that I had two Models called User and Comment
And there is a column called comment in User Table.
and in association, this is steted
user.rb
has_one :comment
comment.rb
belongs_to :user
What’s going to be fetched if I code like this in controller?
@comment = User.comment
Does it fetch all the associated records from Comment Table?
or does it fetch the content of comment column of User Table???
You have the relationship backward, there should be a ‘user_id’ column in the ‘comments’ table. Then your controller code will work as expected – it will fetch the associated comment for that user. And note that the convention for associations is to name the column ‘modelname_id’, not just ‘modelname’