Rails 3, ActiveRecord, PostgreSQL - “.uniq” command doesn't work?

后端 未结 4 1331
轮回少年
轮回少年 2020-12-09 17:51

I have following query:

Article.joins(:themes => [:users]).where([\"articles.user_id != ?\", current_user.id]).order(\"Random()\").limit(15).uniq
<         


        
4条回答
  •  被撕碎了的回忆
    2020-12-09 18:26

    I assume that the .uniq method is translated to a DISTINCT clause on the SQL. PostgreSQL is picky (pickier than MySQL) -- all fields in the select list when using DISTINCT must be present in the ORDER_BY (and GROUP_BY) clauses.

    It's a little unclear what you are attempting to do (a random ordering?). In addition to posting the full SQL sent, if you could explain your objective, that might be helpful in finding an alternative.

提交回复
热议问题