ActiveRecord Join Query and select in Rails

前端 未结 5 1779
甜味超标
甜味超标 2021-01-30 10:34

In my rails 4 application, a client (clients table) can have many projects (projects table). I have a column called name in each table. I am trying to write a

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-30 11:09

    To get both project table name and client name you can do like below query

    Project.joins(:client).pluck(:name,:'clients.name')

提交回复
热议问题