Hi
I have a view that does not really fit that great with my data model and have made longish join for it.
ProjectJob.includes(:job_type,
:job_category,
project_job_rollup: :project_currency, quotations: :quotation_rollups)
.select(:job_number,
:header,
:project_id,
:job_type_id,
:job_category_id,
:quotation_group_id,
:serial,
"quotation_rollups.total_quote as quotation_job_total_quote"
).references(project_job_rollup: :project_currency)
.where(project_id: @project).where(quotations:{is_elected:true})
.order("job_types.order asc")
.order("job_categories.number asc")
.order(:serial)
Which gives me all that data that i need in only one query and no n+1 issues.
What I’m not super happy about is that the generated SQL pulls all 115 columns from all the involved tables. I thought that select was there to only give me the columns that I specified?
Is there something about includes and select that I have not understood correctly? Any points to either documentation or other help to understand this is much appreciated.
Thanks in advance Jens