假设我有一个包含表'posts'和'tags'的简单数据库.帖子可以有很多标签,标签可以属于很多帖子.
构建数据库的最佳方法是什么?我想过使用list/serialize:
tags
idx tag_id, str tag_name
posts
idx post_id, str title, list tag_ids
Run Code Online (Sandbox Code Playgroud)
或者有另一个表与关联.问题是使用这个我甚至不知道如何构建查询以在我收到帖子时提取相关的标签名称.
posts
idx post_id, str title
post_tags
fk post_id, fk tag_id
Run Code Online (Sandbox Code Playgroud)
其实我不喜欢他们中的任何一个.有没有更好的办法?