Adding scope to ActiveRecord causes hierarchy error

Viewed 1083

I've just converted all of my Rails models to use uuid as a primary key replacement, but this breaks the #first and #last methods so I'm trying to add a default scope that sorts by created_at instead of id.

My concern looks like this:

# config/initializers/uuid_support.rb
module 
  extend ActiveSupport::Concern

  included do
    default_scope -> { order 'created_at ASC' }
  end
end
ActiveRecord::Base.send :include, UuidSupport

Once this has been added, the following error gets thrown when performing a fetch on any model: ActiveRecord::ActiveRecordError: ActiveRecord::Base doesn't belong in a hierarchy descending from ActiveRecord.

1 Answers
Related