Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3.2 Rails3:如何通过在_Ruby On Rails 3.2_Postgresql 9.1 - Fatal编程技术网

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)