title: Rails Arel selecting distinct columns
body: <p>I've hit a slight block with the new <code>scope</code> methods (Arel 0.4.0, Rails 3.0.0.rc)</p>
  
  <p>Basically I have:</p>
  
  <p>A <code>topics</code> model, which <code>has_many :comments</code>, and a <code>comments</code> model (with a <code>topic_id</code> column) which <code>belongs_to :topics</code>.</p>
  
  <p>I'm trying to fetch a collection of "Hot Topics", i.e. the topics that were most recently commented on. Current code is as follows:</p>
  
  <pre><code># models/comment.rb
  scope :recent, order("comments.created_at DESC")
  
  # models/topic.rb
  scope :hot, joins(:comments) &amp; Comment.recent &amp; limit(5)
  </code></pre>
  
  <p>If I execute <code>Topic.hot.to_sql</code>, the following query is fired:</p>
  
  <pre><code>SELECT "topics".* FROM "topics" INNER JOIN "comments"
  ON "comments"."topic_id" = "topics"."id"
  ORDER BY comments.created_at DESC LIMIT 5
  </code></pre>
  
  <p>This works fine, but it potentially returns duplicate topics - If topic #3 was recently commented on several times, it would be returned several times.</p>
  
  <p><strong>My question</strong></p>
  
  <p>How would I go about returning a distinct set of topics, bearing in mind that I still need to access the <code>comments.created_at</code> field, to display how long ago the last post was? I would imagine something along the lines of <code>distinct</code> or <code>group_by</code>, but I'm not too sure how best to go about it.</p>
  
  <p>Any advice / suggestions are much appreciated - I've added a 100 rep bounty in hopes of coming to an elegant solution soon.</p>