# frozen_string_literal: true

class ThinkingSphinx::Railtie < Rails::Railtie
  initializer 'thinking_sphinx.initialisation' do
    ActiveSupport.on_load(:active_record) do
      ActiveRecord::Base.send :include, ThinkingSphinx::ActiveRecord::Base
    end
  end

  rake_tasks do
    load File.expand_path('../tasks.rb', __FILE__)
  end
end

# frozen_string_literal: true

class ThinkingSphinx::Railtie < Rails::Railtie
  config.to_prepare do
    ThinkingSphinx::Configuration.reset
  end

  initializer 'thinking_sphinx.initialisation' do
    ActiveSupport.on_load(:active_record) do
      ActiveRecord::Base.send :include, ThinkingSphinx::ActiveRecord::Base
    end
  end

  rake_tasks do
    load File.expand_path('../tasks.rb', __FILE__)
  end
end

Reset configuration when Rails reloads.
Reset configuration when Rails reloads.

I feel like I've hit this problem before, and I thought I'd restructured things in v3 onwards to avoid it, but I guess not. It's reared its head again in #1125 - the cached configuration's indices kept onto their old references to models, whereas models returned from ActiveRecord search calls were using the new references, and thus not quite matching. It wasn't a problem if all models were using the default primary key of 'id', but otherwise with alternative primary keys things would break.
