.distinct or .uniq

suggest change

To drop duplicate rows from a relation, use distinct:

Customer.select(:country).distinct

The query is:

SELECT DISTINCT "customers"."country" FROM "customers"

On a relation, uniq did the same thing. It was deprecated in Rails 5.0 and removed in Rails 5.1, because it is easy to confuse with Array#uniq and with the word “unique”. distinct matches the SQL keyword. Array#uniq is unchanged.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents