Skip to content

Commit ea35340

Browse files
committed
fix: load ActiveRecord component after Rails init
This isn't quite as neat as ea8bc34 (as I like the idea of waiting until ActiveRecord is loaded by Rails itself), but it seems Rake tasks don't always load ActiveRecord, and so we end up in a situation where indices are being loaded without TS's ActiveRecord components being available (see #1199). But: the main issue was that prior to @jdelStrother's good work, AR configuration in initialisers was being ignored. This new approach waits until after initialisers have been run, so it should be fine.
1 parent c8f8e73 commit ea35340

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/thinking_sphinx/railtie.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ class ThinkingSphinx::Railtie < Rails::Railtie
55
ThinkingSphinx::Configuration.reset
66
end
77

8-
initializer 'thinking_sphinx.initialisation' do
9-
ActiveSupport.on_load(:active_record) do
10-
require 'thinking_sphinx/active_record'
11-
ActiveRecord::Base.include ThinkingSphinx::ActiveRecord::Base
12-
end
8+
config.after_initialize do
9+
require 'thinking_sphinx/active_record'
10+
ActiveRecord::Base.include ThinkingSphinx::ActiveRecord::Base
11+
end
1312

13+
initializer 'thinking_sphinx.initialisation' do
1414
if ActiveSupport::VERSION::MAJOR > 5
1515
if Rails.application.config.autoloader == :zeitwerk
1616
ActiveSupport::Dependencies.autoload_paths.delete(

0 commit comments

Comments
 (0)