title: Modeling Messages between Users
body: <p>I want to model messages between users, here is the requirement:</p>
  
  <ol>
  <li><p>User has received and sent messages, and should be retrieved by <code>user.received_messages</code> and <code>user.sent_messages</code></p></li>
  <li><p>Message has sender and receiver, and should be retrieved by <code>message.sender</code> and <code>message.receiver</code>.</p></li>
  </ol>
  
  <p>I have created the User model as:</p>
  
  <pre><code>script/generate model User name:string
  </code></pre>
  
  <p>and Message model as:</p>
  
  <pre><code>script/generate model Message content:text sender_id:integer receiver_id:integer
  </code></pre>
  
  <p>I have come up with the Message like below, and it works as wish</p>
  
  <pre><code>class Message &lt; ActiveRecord::Base
      belongs_to :sender, :class_name=&gt;'User', :foreign_key=&gt;'sender_id'
      belongs_to :receiver, :class_name=&gt;'User', :foreign_key=&gt;'receiver_id'
  end
  </code></pre>
  
  <p>but I don't know how to model the User, any advise is appreciated.</p>