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部分