title: Rails select subquery (without finder_sql, if possible)
body: <p>I have an model called Object (doesn't really matter what it is)</p>
  
  <p>It has a default price (column is called "price"). </p>
  
  <p>And then there is a Schedule object that allows to override the price for specific dates.</p>
  
  <p>I want to be able to determine the MINIMUM price (which is by definition the MINIMUM between the default and "current" price) during the SQL-query just in order to be able to ORDER BY the calculated minimum price</p>
  
  <p>I want to make my search query as efficient as possible and I was wondering if I can
  do something like that: </p>
  
  <pre><code>Object.select("id AS p_id, id, (SELECT MIN(`schedules`.`price`) FROM `schedules` WHERE `schedules`.`object_id` = p_id`) AS objects.min_price").limit(5)
  </code></pre>
  
  <p>But, it generates an odd SQL that looks like this: </p>
  
  <pre><code>SELECT `objects`.`id` AS t0_r0, `objects`.`title` AS t0_r1, `objects`.`created_at` AS t0_r2, `objects`.`updated_at` AS t0_r3, `objects`.`preferences` AS t0_r4 ........ (a lot of columns here) ... ` WHERE `objects`.`id` IN (1, 2, 3, 4 ....)
  </code></pre>
  
  <hr>
  
  <p>So, as you can see it doesn't work. First of all - it loads all the columns from the objects table, and second of all - it looks horrible.</p>
  
  <p>The reason why I don't want to use finder_sql is that I have a lot of optional parameters and stuff, so using the AR::Relation object is highly preferred prior to fetching the results themselves. </p>
  
  <p>In addition to abovementioned, I have a lot of records in the DB, and I think that loading them all into the memory is not a good idea and that is the main reason why I want to perform this subquery - just to filter-out as many records as possible.</p>
  
  <p>Can someone help me how to do it more efficiently ?</p>