Rails: Table join with specified fields in select

programming

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 is the gist I created:

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

Add the first comment

Leave a Reply

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>