0

I'm trying to clean up some queries on an app I work on. Right now I'm performing 4 queries to the same table for very similar information

MyModel.order("for_date ASC").where('boolean_column_1 = ?', 'Y').last
MyModel.order("for_date ASC").where('boolean_column_2 = ?', 'Y').last
MyModel.order("for_date ASC").where('boolean_column_3 = ?', 'Y').last
MyModel.order("for_date ASC").where('boolean_column_4 = ?', 'Y').last

My question is: what's the best way to clean this up? I'd like to keep it to only 4 values returned, because it's a big table. I can't think of a good way to reduce this to one query

ruby version 2.1, rails version 3.2

Brad Werth
  • 16,916
  • 9
  • 62
  • 86
Andrew Algard
  • 95
  • 1
  • 11

0 Answers0