I have the following association:
Artist has_many Songs. Hence, I can get an artist's songs by doing:
However, I would like to get only the songs' genre:
But, this genre may appear multiple times in the results; I would only like to get unique genre values. Unfortunately,
pluck isn't of any help here, since it returns an array, and calling
uniq on it won't tweak the ActiveRecord query, but the plain
I can do it like this:
but I feel there must be a better way.
P.S.: From some minimal benchmarks, however,
pluck + Array#uniq seems a bit faster than
select + uniq + pluck.