I heard that the many-to-many relationship should be avoided and reduced to one-to-many. Is it true? And why should you do that?

  • And you could not give an example of how a many-to-many relationship can be reduced to a one-to-many relationship. Because all the connections in Mm that come to my mind cannot be otherwise expressed. And where did you by the way read such nonsense? Maybe they want to say that they should not be fenced up there, where in principle it does not belong to her? - Mike
  • For example, there are tables sites and filter_rules (sites that need to be parsed, and filter rules for paths that can be parsed, something like robots.txt). Many-to-many option: each site may have several filtering rules, and vice versa. A third table, sites_filter_rules . One-to-many option: site_id column appears in the table with rules. And if two sites use the same rule, then this rule is duplicated in the table, only the site_id column is different. - melihovv
  • In this situation, I would proceed from where the rules appear and how they are used. If a person enters the rules and it is convenient for him to simply type them from the directory and they are often duplicated - then mm. If the rules are automatically created based on robots.txt reading, then oh. Although in this case, maybe m-m entered to reduce the size of the table. As for me, once in a robots.txt path and they are set on each site independently, then it looks more like life. And if we ourselves bring a bunch of extra hands. information in the record and it repeats, then doing ohm we bring redundancy to the database, which leads to typing errors - Mike

1 answer 1

Probably it means that when, for example, you have a table of articles and a table of tags, then:

  • It would be wrong to add additional columns to the table of articles for a number of tags of the form ID тега 1 , ID тега 2 , ID тега 3

  • It will be correct to create another table of the type of ID связи ID статьи - ID статьи ID тега - ID тега

Why it is so easy to see trying to search for tags in either case.