Case Statements in ARel
问题 I'm trying to clean up an ActiveRecord code written with MySQL case statements using ARel. I know Arel is able to handle case statements, but not sure how to use it. So I have an orders table with quantity and user_id(foreign key) columns. I'm dynamically computing the price of orders as there are different pricing schemes based on the quantity ordered. This is what the AR code looks like: def orders_with_price <<-SQL orders.*, SUM(CASE orders.quantity WHEN 2 THEN 500 * orders.quantity WHEN 5