title: rails, retrieve another user object besides foreign key
body: <p>i have a user model and a message model. my user has_many messages and my message belongs_to user.</p>
  
  <p>on my message model, i have the attributes :content, :user_id, :to_id.</p>
  
  <p>the :user_id acts as the foreign key, and can also be thought of as the 'sender' while the :to_id can be thought of as the 'receiver'.</p>
  
  <p>in my message index template, when im trying to display all the messages, i do something like...</p>
  
  <pre><code>&lt;%= link_to message_item.user.name, message_item.user %&gt;
  </code></pre>
  
  <p>that line works great when showing my received messages (where im the :to_id and :user_id is showing who sent me the message)</p>
  
  <p>however, when im listing the messages under my 'sent' category, doing the line of code above will always show my name (because im :user_id) as opposed to the :to_id, which would make more sense.</p>
  
  <p>ideally i would want something like </p>
  
  <pre><code>&lt;%= message_item.to_id %&gt;
  </code></pre>
  
  <p>for my sent category. is there a way to get the user object mentioned in my :to_id category?
  something like message_item.to_id.name wouldn't work because message_item.to_id returns back an integer and not the user object. is there a way to get it?</p>
  
  <p>at trying to display and linking to the sender, here is my failed attempt</p>
  
  <pre><code>    &lt;% if current_user == message_item.user %&gt;
      &lt;%= message_item.to_id %&gt;
      &lt;% else %&gt;
          &lt;%= link_to message_item.user.name, message_item.user %&gt;
      &lt;% end %&gt;
  </code></pre>
  
  <p>thanks</p>