Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.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 使用Rails时出现Postgresql错误';uniq法_Ruby On Rails_Postgresql_Uniq_Hstore - Fatal编程技术网

Ruby on rails 使用Rails时出现Postgresql错误';uniq法

Ruby on rails 使用Rails时出现Postgresql错误';uniq法,ruby-on-rails,postgresql,uniq,hstore,Ruby On Rails,Postgresql,Uniq,Hstore,我有一个项目模型,它属于产品模型产品有一个hstore类型的属性列。我想返回一组属于某个产品且不包括当前项目的唯一项目:@item。类似的\u项目 class Item < ActiveRecord::Base belongs_to :product scope :by_platform, ->(value) { joins(:product).merge(Product.by_platform(value)) } scope :by_genre, ->(value

我有一个
项目
模型,它属于
产品
模型<代码>产品有一个hstore类型的
属性
列。我想返回一组属于某个产品且不包括当前项目的唯一
项目
@item。类似的\u项目

class Item < ActiveRecord::Base
  belongs_to :product
  scope :by_platform, ->(value) { joins(:product).merge(Product.by_platform(value)) }
  scope :by_genre, ->(value) { joins(:product).merge(Product.by_genre(value)) }

  def similar_items
    Item.includes(:product)
      .by_platform(self.product_platform)
      .by_genre(self.product_genre)
      .limit(3).where.not(product: self.product)
      .order("(properties -> 'release_date')::date DESC")
      .uniq
  end
end

class Product < ActiveRecord::Base
  store_accessor :properties, :platform, :genre
  has_many :items

  scope :by_platform, ->(value) { where("properties @> hstore('platform', ?)", value) }
  scope :by_genre, ->(value) { where("properties @> hstore('genre', ?)", value) }
end

正如错误消息所述

test=> select distinct id from test order by f;
ERROR:  for SELECT DISTINCT, ORDER BY expressions must appear in select list
LINE 1: select distinct id from test order by f;

将您的排序列添加到语句的select部分。

错误消息指出

test=> select distinct id from test order by f;
ERROR:  for SELECT DISTINCT, ORDER BY expressions must appear in select list
LINE 1: select distinct id from test order by f;
将排序列添加到语句的select部分