我正在寻找构建一个处理对话的消息传递系统,就像Facebook一样。我想知道关于表结构的最佳方法是什么。我会有一张表:
id reply_id - the id of the original message that started the conversation to_id from_id subject content date_sent read_status
或两个表:
table 1 - for the start of new messages id to_id from_id subject content date_sent read_status table 2 - when someone replies to a message id message_id to_id from_id subject content date_sent read_status
答案 0 :(得分:2)
答案 1 :(得分:2)
这取决于很多事情,但是第一次猜测尝试可能是“消息”的自我引用表。例如:
message:
sender_id: User
recipient_id: User
in_reply_to_id: Message
subject, content, etc
消息如下:
belongs_to :sender, :class => 'User'
belongs_to :recipient, :class => 'User'
has_many :replies, :dependent => :destroy
belongs_to :in_reply_to, :class => 'Message'
这将允许您构建一个回复树(因为一条消息可以in_reply_to一条消息,而这又可能是in_reply_to另一条消息)。您可能还需要考虑使用acts_as_ordered_tree之类的内容来获得更多的灵活性和控制权。
答案 2 :(得分:-5)
真正的最佳答案是:MySQL是构建电子邮件和聊天类型系统的极其糟糕的工具。
邮件系统已经存在。聊天系统已经存在。你为什么试图重新发明轮子?