Rails 3 Joins -- Select only certain columns

activerecord, ruby, ruby-on-rails

Solution

You could use something like this:

@comments = Comment.joins(:user)
                   .select("comments.*, users.first_name")
                   .where(study_id: @study.id)

Problem

Below is a relationship between Comments and a user. Each comment has one user so I'm building out a join in the code below. I was wondering how to build this code to only include specific columns in the join. I don't need all of the user information. Just the first_name. Any suggestions. Current Code: ``` @comments = Comment.where(:study_id => @study.id).joins(:user) ```

Original source