ruby on rails - What is the relationship between these two tables in RoR? -


I am developing applications like a stack overflow, questions or articles are at a lesser tag and one tag or one There should be more articles.

So, I am doing this in Migration to RoR. I think which relationship is appropriate for both tables should use "has_many" in the article table, and in the tag table, "has_many" should be used, but I am thinking that in the middle, another table It is necessary to add, something like that ....

So, the first one is:

  class article & lt; ActiveRecord :: Base has has_many: Tag end class tag & lt; ActiveRecord :: Base is has_many: articles end  

or something like this:

  class articles & lt; ActiveRecord :: Base has has_many: articleTagList has_many: tags, via = & gt; : Article tag list end class tag & lt; ActiveRecord :: Base has has_many: articleTagList has_many: Article, via = & gt; : Article Tag List End Category Graphs & lt; ActiveRecord :: Base is_to: article is_to: tag end  

Many-to-many relationships Always a third "look-up table" will be required in the normalized database.

If you deny, you can remove them with a tag with a delimiter in a field with a delimiter. But you also have to give an argument to handle recovery.

I personally want to go with the generalized option.


Comments