Ruby on rails 3.2 Rails3:如何通过在
我的应用程序中有两个模型:用户和视图,视图为:Ruby on rails 3.2 Rails3:如何通过在,ruby-on-rails-3.2,postgresql-9.1,Ruby On Rails 3.2,Postgresql 9.1,我的应用程序中有两个模型:用户和视图,视图为: class View < ActiveRecord::Base attr_accessible :user_id, :viewable belongs_to :viewable, polymorphic: true, counter_cache: true end 但是我仍然有重复的记录。使用内部连接或左连接,尝试一下它,你会怎么做…?你尝试过.uniq方法吗? u = User.find 1 View.where(
class View < ActiveRecord::Base
attr_accessible :user_id, :viewable
belongs_to :viewable, polymorphic: true, counter_cache: true
end
但是我仍然有重复的记录。使用内部连接或左连接,尝试一下它,你会怎么做…?你尝试过
.uniq
方法吗?
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)