← Back to Upcase

Unique commenters on an article


(Josh Smith) #1

I have an Article which has_many :comments, and Comment belongs_to :article and :user. I was wondering what the most efficient Arel query would be to get the unique users who commented on a given article.

Thanks!


(Ben Orenstein) #2

This StackOverflow post seems to answer this question well: http://stackoverflow.com/questions/5125209/how-to-fetch-distinct-values-with-arel-relational-algebra-and-has-many-through