2011-04-20 38 views

回答

0

我覺得這裏最好的和最性能比較解決方案是使用touch選項:

class Post < ActiveRecord 
    belongs_to :thread, :touch => true 
end 

所以,你將能找到最後一個活動主題簡單:

Thread.order("updated_at DESC").limit(10) 

怎麼樣查詢...您可以嘗試通過子對象找到它:

active_threads = Post.includes(:threads).order("created_at DESC").all.map(&:thread).uniq