I need to add article to multiple category
for example I have article name ‘test article’ need to add it to category 1 and category2
need to know how to make relationship between to tables for this
note : in the past I make row in article database table name ‘category’ and add category id like 1,2,3 but this make problem in search and list please help me about that
You need three tables:
articlescategoriescategories_per_article. This table often is called a Junction table or a Association table.Example data:
You will see that article 1 (Fuzz) has three categories, and article 2 (Bizz) only has category 1. We call this a many-to-many relationship (or n-to-n, for example in ER or UML), because article 1 has multiple categories, and category 1 is used by multiple articles.
You can do all possible queries using this schema – feel free to ask in comments for specific examples (like
How do I get all articles which have categories 1 and 3 but not 2).