鍍金池/ 問答/數(shù)據(jù)庫  網(wǎng)絡(luò)安全/ 聊天記錄表結(jié)構(gòu)設(shè)計(jì)之關(guān)于私聊消息的表設(shè)計(jì)

聊天記錄表結(jié)構(gòu)設(shè)計(jì)之關(guān)于私聊消息的表設(shè)計(jì)

有如下表
消息記錄
msg_record
from_id:發(fā)送者id
to_id:接收方id
msg:消息內(nèi)容
msg_type:消息類型[文本圖片]

用戶表
user_info
id 用戶id
nick 用戶昵稱
header 頭像
sex 性別

user_to_user
私聊對(duì)象
from_id發(fā)送者id
to_id 對(duì)方id【此處是1多關(guān)系】

每次查看私聊消息列表只要
select to_id from user_to_user where from_id = id
一個(gè)人可能和多個(gè)人聊天,但是同時(shí)多個(gè)人也可能和一個(gè)人聊天
那么假如存在一條記錄 {from_id:1,to_id:2}
是否要同時(shí)在表中插入一條{from_id:2,to_id:1}
否則select to_id from user_to_user where from_id = 2將查不到數(shù)據(jù),
請(qǐng)問這個(gè)設(shè)計(jì)問題該如何解決?
請(qǐng)教高手!

回答
編輯回答
做不到
每次查看私聊消息列表只要
select to_id from user_to_user where from_id = id

這只是“我發(fā)出的消息”,不是“私聊消息列表”。

2017年9月22日 07:32