Rails 3 Joins — Select only certain columns

后端 未结 2 1240
情话喂你
情话喂你 2020-12-30 03:59

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

2条回答
  •  渐次进展
    2020-12-30 04:32

    You could use something like this:

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

提交回复
热议问题