Note that there are some explanatory texts on larger screens.

plurals
  1. PORails private message system
    text
    copied!<p>Hey, I'm trying to implement a message system as used in social networks. The problem I'm facing is first about the database structure and second how to implement it in rails.<br> My first idea is I'm using 3 tables:</p> <p>messages: id|subject|text|created_at<br> receivers: id|message_id|read:boolean<br> creators: id|message_id|read:boolean </p> <p>now I'm wondering how to implement following features:<br> 1.) a user can delete his message. but as both want to read the message, how to make sure the message is only deleted when both users have deleted it.<br> 2.) how do I implement a reply? or actually how do I find the corresponding creator?<br> 3.) how to find out whether a mail was read by the receiver? </p> <p>another idea is: creator_messages: id|creator_id|receiver_id|subject|text|read|created_at receiver_messages: same as creator_messages </p> <p>this distinguishes between the users, so they can delete individually their messages. but how do i find out, whether the mail was read or not?</p> <p>my third approach was basicly my second but only one table messages and then displaying this to the user.<br> 1. the message is deleted as soon as one of the user deletes it.<br> 2. actually how do I represent the relationships as has_many and belongs to?</p> <p>I thought it would work like this: </p> <pre><code>model User :has_many :send_messages, :class_name=&gt;"messages", :foreign_key=&gt;"creator_id" :has_many :received_messages, :class_name=&gt;"messages", :foreign_key=&gt;"receiver_id" end model Messages belongs_to :user end </code></pre> <p>but somehow I didn't get it to work. guess I'm missing something basic here.</p> <p>Hope someone can help me =) thanks a lot</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload