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)
但我仍然有重複記錄。
您是否試過'.uniq'方法? –