Tag: 消息传递

在rails 3中模拟用户的消息

我构建了以下模型来处理用户的消息交换: create_table “messages”, :force => true do |t| t.integer “source_id” t.integer “destination_id” t.string “object” t.string “body” t.datetime “created_at” t.datetime “updated_at” end 这些是它的联想: class Message ‘User’, :foreign_key=>’source_id’ belongs_to :reciever, :class_name=>’User’, :foreign_key=>’destination_id’ end 而这些是另一方的关联(用户模型): has_many :sent_messages, :class_name=> ‘Message’, :foreign_key=>’source_id’, :dependent=>:destroy has_many :recieved_messages, :class_name=> ‘Message’, :foreign_key=>’destination_id’, :dependent=>:destroy 该模型是正确的并且正常工作,实际上从我可以检索的消息中,谁是发送者,谁是接收者,从用户,我可以获得所有发送和接收的消息。 不幸的是,它不处理任何情况:如果接收者或发送者删除消息怎么办? 消息是独一无二的,所以它在两边都消失了(坏事)。 如何知道其中一方是否已阅读该消息? 有什么建议吗? 你认为我必须重新计划吗? TNX