title: Selecting columns from several tables in Rails 3
body: <p>I'm new to ORM in general and I'm having trouble getting Rails to generate ok SQL. I have two tables, messages and users. Basically, I want a list of the messages with the <code>user_name</code> of the senders tacked on.</p>
  
  <p>It would be great if:</p>
  
  <ul>
  <li><p>I only got that one column from the user table (the user table has   lots of columns that don't need to get selected)  </p></li>
  <li><p>It used a LEFT JOIN (I want messages even if the users are gone for some reason, and I don't want to slow things down with an INNER JOIN) </p></li>
  <li><p>I don't need to mention the names of the foriegn keys in this code (I should only        have to set those up in the models and "NOT REPEAT MYSELF", right?)</p></li>
  </ul>
  
  <p>I have these models set up:</p>
  
  <pre><code>class Message &lt; ActiveRecord::Base
    belongs_to :sender, :class_name =&gt; "User", :foreign_key =&gt; "from_user_id"
    belongs_to :recipient, :class_name =&gt; "User", :foreign_key =&gt; "to_user_id"
  end
  
  
  class User &lt; ActiveRecord::Base
    has_many :sent_messages, :class_name =&gt; "Message", :foreign_key =&gt; "from_user_id"
    has_many :received_messages, :class_name =&gt; "Message", :foreign_key =&gt; "to_user_id"
  end
  </code></pre>
  
  <p>I really WANT to like ORM, but it seems like it's so easy to get to the point where you just have to write the queries yourself.</p>