title: Which type of Rails model association should I use in this situation?
body: <p>I have two models/tables in my Rails application: discussions and comments. Each discussion <code>has_many</code> comments, and each comment <code>belongs_to</code> a discussion. My discussions table also includes a <code>first_comment_id</code> column and <code>last_comment_id</code> column for convenience and speed. I want to be able to call <code>discussion.last_comment</code> for the last comment model, but the following (in my discussion model) isn't working to make this happen:</p>
  
  <pre><code>has_one :first_comment, :class_name =&gt; "Comment"
  has_one :last_comment, :class_name =&gt; "Comment"
  </code></pre>
  
  <p>When I call <code>discussion.last_comment</code>, the following SQL is run:</p>
  
  <pre><code>SELECT * FROM `comments` WHERE (`comments`.discussion_id = 1) LIMIT 1
  </code></pre>
  
  <p>It's using the <code>discussions.id</code> column to join against <code>comments.discussion_id</code>, when I want it to join <code>discussions.last_comment_id</code> against <code>comments.id</code>.</p>
  
  <p>Am I using the wrong type of association here? Thanks for your help!</p>