I want to select users from the users table based on:
user.created
user.sales_count
So I want to fetch all users, sometimes ordered by created date, and sometimes based on sales_count. And I want to be able to switch between ASC or DESC order.
All queries need to have this WHERE clause:
WHERE region = 123
How can I build my active record query to support these order by conditions?
options[:order_col] ||=is really saying:options[:order_col] = options[:order_col] || ""which in english is saying set
options[:order_col]tooptions[:order_col]if set, other wise"". We can set the order_type to""because SQL will by default order results ASC.Example: