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
  • 17,411
  • 10
  • 63
  • 88
Andrew Algard
  • 105
  • 1
  • 12

0 Answers0