相关疑难解决方法(0)

Rails 3,ActiveRecord,PostgreSQL - ".uniq"命令不起作用?

我有以下查询:

Article.joins(:themes => [:users]).where(["articles.user_id != ?", current_user.id]).order("Random()").limit(15).uniq
Run Code Online (Sandbox Code Playgroud)

并给我错误

PG::Error: ERROR:  for SELECT DISTINCT, ORDER BY expressions must appear in select list
LINE 1: ...s"."user_id" WHERE (articles.user_id != 1) ORDER BY Random() L...
Run Code Online (Sandbox Code Playgroud)

当我将原始查询更新

Article.joins(:themes => [:users]).where(["articles.user_id != ?", current_user.id]).order("Random()").limit(15)#.uniq
Run Code Online (Sandbox Code Playgroud)

所以错误消失了...在MySQL .uniq工作,在PostgreSQL中没有.存在任何替代方案?

database postgresql activerecord uniq ruby-on-rails-3

16
推荐指数
1
解决办法
8324
查看次数