Answer the question
In order to leave comments, you need to log in
Postgreas unique and order by conflict, what's wrong?
The expression of the form .joins(:user => :profile).order_site_rating
gives duplicates, how and why I have not figured it out yet, if you tell me, I will also be glad.
The problem is the following
PG conflicts if we just add distinct
joins(:user => :profile).order_site_rating.distinct
SELECT DISTINCT(users.id), users.*, profiles.first_name FROM users LEFT JOIN profiles ON users.id = profiles.user_id ORDER BY profiles.first_name
order('case when profiles.avatar is null then -1 else 1 end desc')
Answer the question
In order to leave comments, you need to log in
ERROR: in a SELECT DISTINCT construct, the ORDER BY expressions must be in the select list
LINE 1: ...("anketa_owners"."town_id" IS NOT NULL) ORDER BY case when ...
^
: SELECT DISTINCT "anketa_owners".* FROM " anketa_owners" INNER JOIN "users" ON "users"."id" = "anketa_owners"."user_id" INNER JOIN "profiles" ON "profiles"."user_id" = "users"."id" WHERE ("anketa_owners". "town_id" IS NOT NULL) ORDER BY case when profiles.avatar is null then -1 else 1 end desc, profiles.rating DESC LIMIT 10 OFFSET 0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question