Rails - Table Join With Specified Fields in Select
Figured this out after a lot of monkeying-around (I mean script/console
).
Situation:
- I have two tables (Revisions
has_many
Inputs) - I can load Revisions and then for each I can find Inputs, but quickly found out that for my situation, it leads to a lot of queries. So I want to load the required fields from both tables together
:joins
is the only way to do this, using :includes
does NOT respect the select clause. Here a gist:
Admittedly, this is hacky, too hacky for my comfort. Comment/suggest a better/cleaner solution?
Note: Found out that there is a gem to do this: ar-select-with-include