gpt4 book ai didi

mysql - 对话消息系统的表结构

转载 作者:可可西里 更新时间:2023-11-01 07:45:41 24 4
gpt4 key购买 nike

我希望构建一个处理对话的消息传递系统,就像 Facebook 的处理方式一样。我想知道在表结构方面最好的方法是什么。我要一张像这样的 table 吗:

idreply_id - the id of the original message that started the conversationto_idfrom_idsubjectcontentdate_sentread_status

或者两个表:

table 1 - for the start of new messagesidto_idfrom_idsubjectcontentdate_sentread_statustable 2 - when someone replies to a messageidmessage_idto_idfrom_idsubjectcontentdate_sentread_status

最佳答案

这取决于很多因素,但初步猜测可能是“消息”的自引用表。例如:

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 的东西以获得更大的灵 active 和控制力。

关于mysql - 对话消息系统的表结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11284858/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com