Skip to content


Subversion checkout URL

You can clone with
Download ZIP


ActiveRecord::QueryMethods#reorder with nil argument still removes the default_scope order #14308

jhephs opened this Issue · 4 comments

3 participants


I'm using Rails 4.1.0.rc1 and I have the following

class User < ActiveRecord::Base
  default_scope { order(:created_at => :desc) }

class UsersController < ApplicationController
  def index
    @users = User.reorder(params[:order])

> User.all.to_sql
 => "SELECT `users`.* FROM `users`   ORDER BY `users`.`created_at` DESC"
> User.reorder(nil).to_sql
 => "SELECT `users`.* FROM `users`"

I don't know if this is more of a feature request but I'm guessing that this is somehow common. I expect the reorder method not to remove the default order if the passed argument is nil.


reorder(nil) is common way to clean order, so this is expected behaviour.


@pftg Can't we use except(:order) or unscope(:order) to clean order instead?


#reorder is meant to remove all existing orders:

# Replaces *any* existing order defined on the relation with the specified order.

You can post your feature request to the rails-core mailing list as pointed by @pftg but I'm not sure that this is worth and actually achievable to be honest. Thank you guys!

@robin850 robin850 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.