我不会继续使用 GUID / UID / 全局唯一标识符。相反,我会在主消息表和存储要评论的实体的单个表之间创建映射表。
每次插入到评论表中都会有一个 ID,然后该 ID 将被插入到包含要评论的原始实体的 ID 和评论 ID 的映射表中。
例如
产品:
id
name
产品评论
product_id
comment_id
另一张桌子
id
anothervalue
anothertable_comments
some_id
comment_id
comments table
id
comment
The reason I would use a mapping table is because you would be required to create a new global identifier in each of your existing tables. The mapping table would also allow a many – many as well as a one to one relationship so someone could apply the same comment to more than one existing table.
Edit:
Single mapping table:
If there are lots of tables you want to add this to you can just create a single mapping table. For example:
comments_table
id
comment
table_map
table_name
table_id
comment_id
This way you would add the table name and the id of the row along with the comment id to this single mapping table. This reduces the number of tables you have to insert but you must then think about appropriate indexing for performance reasons as you don’t want to do a full table scan on mapping tables.