D
D
Dmitry Khaperets2015-09-05 11:54:05
Yii
Dmitry Khaperets, 2015-09-05 11:54:05

What is the best way to organize communication: article-category?

I am using Yii2.
There is a model Article (article) and Category (category).
What is the best way to organize communication between them?
Options:
1. In the Article model, add the category_id field, where we enter the category ID.
2. Add an intermediate table articles_categories (category_id, article_id).
The advantage of the first option is the ease of working with categories and related articles.
Advantages of the second option: flexibility, no need to modify the Article when adding similar links (tags, authors, etc.), you can add several categories to one article.
I tend to the second option, but I want to hear your opinion.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
index0h, 2015-09-05
@Khaperets

Depends on TK. If the article can be in several categories - Many-Many. If guaranteed in one - One-Many.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question