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
name
Try This:
sql = Project.joins(:client).select(:id, :name, :"clients.name AS client_name").to_sql data = ActiveRecord::Base.connection.exec_query(sql)
OUTPUT
[ {"id"=>1, "name"=>"ProjectName1", "client_name"=>"ClientName1"}, {"id"=>2, "name"=>"ProjectName2", "client_name"=>"ClientName2"} ]