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
If the column in select
is not one of the attributes of the model on which the select
is called on then those columns are not displayed. All of these attributes are still contained in the objects within AR::Relation
and are accessible as any other public instance attributes.
You could verify this by calling first.client_name
:
Project.joins(:client)
.select('projects.id,projects.name,clients.name as client_name')
.first.client_name