Skip to content

Instantly share code, notes, and snippets.

@blasterpal
Created March 5, 2013 12:30
Show Gist options
  • Select an option

  • Save blasterpal/5089998 to your computer and use it in GitHub Desktop.

Select an option

Save blasterpal/5089998 to your computer and use it in GitHub Desktop.
Add default_scope to sort by :id for MySQL -> PostgreSQL migration, working version Rails 3.1.x
# Add to initializer
module SortedById
extend ActiveSupport::Concern
included do
default_scope order('id ASC')
end
end
Rails.application.eager_load!
models = ActiveRecord::Base.subclasses.collect {|ea| ea.name}
models.each do |mod|
Module.class_eval(mod).send(:include,SortedById)
end
@cmar

cmar commented Mar 5, 2013

Copy link
Copy Markdown

Was there a reason you didn't declare the default_scope on ActiveRecord::Base ?

   ActiveRecord::Base.class_eval do
      default_scope order('id ASC')
   end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment