Say I have an article model, user model and comment model. If I want to get all users that commented on a particular article is this the best way or is there a better way?
User.find(Article.first.comments.pluck(:user_id))
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have a few options.
You can add
to
Articlethen just say:If you don’t want to do that for some reason you can do
I think this would be more efficient:
I hope that helps.