2013-10-14 15 views
0

有2種型號在我的應用程序:用戶和視圖,視圖是:Rails3中:如何通過created_at得到重複的記錄和秩序

class View < ActiveRecord::Base 
    attr_accessible :user_id, :viewable 
    belongs_to :viewable, polymorphic: true, counter_cache: true 
end 

我想最後的意見,但由不同的USER_ID :

u = User.find 1 
    View.where(viewable_id: u.id, viewable_type: u.class.name). 
     select("DISTINCT(user_id), created_at").order('created_at desc').limit(10) 

但我仍然有重複記錄。

+0

您是否試過'.uniq'方法? –

回答

0

使用內連接還是左連接,試試吧

+0

那麼,人們會怎麼做......? –