As the error states for SELECT DISTINCT, ORDER BY expressions must appear in select list
.
Therefore, you must explicitly select for the clause you are ordering by.
Here is an example, it is similar to your case but generalize a bit.
Article.select('articles.*, RANDOM()')
.joins(:users)
.where(:column => 'whatever')
.order('Random()')
.uniq
.limit(15)
So, explicitly include your ORDER BY
clause (in this case RANDOM()
) using .select()
. As shown above, in order for your query to return the Article attributes, you must explicitly select them also.
I hope this helps; good luck
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…