Answer the question
In order to leave comments, you need to log in
How to correctly implement a database table to create tags on a website?
I have no experience writing backend sites, and therefore I ask for help.
As I see it:
- a tags table with id, title and slug fields;
- a link table with tag_id and article_id fields;
- and of course, an articles table with a bunch of fields and a field id;
Recommend best practices (articles or right here) where I could see how this is implemented. Looking for a quick solution. Tags means tags under articles (like on a toaster). I would google, but I can’t. Thanks for the answers
Answer the question
In order to leave comments, you need to log in
And why such an overhead?
In the object table, add the string "tags", where in the line there are tags through some kind of separator.
Use this field to display tags on the page
. In the tag_object table, the string field tag, and the object id to search for specific tags.
Plus, I would also keep a tags table, where there would be a list of all unique tags with the number of uses.
Why do you need id for tags? About slug - if you need to search by transliterated tag, then shove it there in tag_object.
If you have 10,000 objects and 1,000 tags, how many entries would you have in the tag_object table in the worst case? In your case, in order to simply get a list of tags for an object, you will need to have so many hemorrhoids - okay, if it’s for one record (and then nothing good). What if it's on the list? Yes, with pagination? Join table with 10000000 for list of tags?
You described the classic many-to-many relationship through an intermediate table, what else can you think of? This is best practices... Just don't forget to set up foreign keys restrictions on the intermediate table in mysql.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question