I have a rails app with articles and author model. If I have an author and a post and want to indicate that the author should be the owner of the article, or that the article belongs to the author, what ist the best practice to do so? In particular:
Does it make a difference if I set
my_article.author_id = author_one.id
or If I do
author_one << my_article
The associations that are used are
- Author has_many articles
- Articles belongs_to Author
And, by the way, what would be the best way to look it up if similar questions appear?
There is not difference between the 3 following:
To set the owner of a particular post, the most common and readable way would be:
OR shorter version: