mysql - How can I include a field that is not part of the group clause in a ActiveRecord query? -
(ruby 1.9.3-p429; rails 3.0.6) recent changes way queue our tests have rendered our last_ids scope: last_ids = tests.where('end_time != 0'). group(:condition1, :condition2, :condition3, :condition4). select('max(id) id') logically obsolete. previously, tests queued , completed in same order test record created maximum id each grouping latest test record. now, efficiency, have queuing algorithm no longer guarantees order of tests. have added "end_time" column test table. solution, far slow use: max_end_times = tests.where('end_time != 0'). group(:condition1, :condition2, :condition3, :condition4). .maximum(:end_time) which yields hash: {[:condition0, :condition1, :condition2, :condition3]=>:endtime}. follows: hash.each_pair |key, value| last_ids << tests.select(:id). where(condition0: [key[0]]). where(con