Bertrand Caron
Bertrand Caron

Reputation: 2667

ActiveRecord : ordering the output of a where request

I'm trying to order the output of a where ActiveRecord query :

result = Class.where('a = ? AND b = ?', params[:a], params[:b])

I tried chaining order both before and after without succeeding, what am I missing ?

#Not working, the order is not modified compared to previous line
result = Class.where('a = ? AND b = ?', params[:a], params[:b]).order('c DESC') 

Upvotes: 2

Views: 44

Answers (1)

dimuch
dimuch

Reputation: 12818

Try to unscope the model, something like

result = Class.unscoped.where('a = ? AND b = ?', params[:a], params[:b]).order('c DESC')

Or delete the default scope if it is not used elsewhere

Upvotes: 2

Related Questions