我有以下查询:
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中没有.存在任何替代方案?