我有3张桌子
我向我的数据库提交了一个帖子:" Hello #Today is an illusion"
,它创建了下一个:
table_post: id_post | post
3 Hello #Today is an illusion
table_hashtags: id_hashtag | hashtag
1 #Today
table_hashtags_relation: id_relation | id_hashtags | id_post
1 1 3
它会保留主题标签#today
id_hashtag=1
并将其与帖子编号3相关联
如果我将帖子编辑为:"Hello #Tomorrow is an illusion"
,则会将#tomorrow
保存为id_hashtag=2
,并将其与第3号帖子相关联。
如何在编辑后的帖子中首先搜索#today
以删除它? (并删除它的关系),以便表格结果如下?
table_post: id_post | post
3 Hello #Tomorrow is an illusion
table_hashtags: id_hashtag | hashtag
2 #Tomorrow
table_hashtags_relation: id_relation | id_hashtags | id_post
2 2 3
答案 0 :(得分:0)
您可以使用id_post查询从table_hashtag_relation检索所有id_relation ..然后您可以查询从table_hashtag中提取所有hashtag ...然后删除所需的#标签。