User has many Posts and many Comments. Posts has many Comments.
If I have @post, how do I get all unique user comments of this post?
For example. User Foo and user Bar have comments on @post. User Foo has 10 comments, while user Bar has 5 comments.
The result only needs to return Foo and Bar. How do I go about this?
I tried the following to no avail:
@post.comments.select('DISTINCT users.email').joins(:user)
Im using MySql by the way.
I’m assuming by “needs to return Foo and Bar” you mean the users Foo and Bar.
If an array will do, consider this:
@post.comments.collect(&:user).uniq