From ea8bc34ef71615523ae4159e851fa514338c14a8 Mon Sep 17 00:00:00 2001 From: Jonathan del Strother Date: Thu, 29 Apr 2021 13:07:18 +0100 Subject: [PATCH] Don't load ActiveRecord during rails initialization If ThinkingSphinx requires ActiveRecord on load, then setting configuration in applications' initializers with have no effect (eg Rails.application.config.active_record.has_many_inversing). Instead, ActiveRecord should be deferred to the end of initialization using Railtie --- lib/thinking_sphinx.rb | 7 +++++-- lib/thinking_sphinx/railtie.rb | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/thinking_sphinx.rb b/lib/thinking_sphinx.rb index 15bc37d4e..2e59e8c66 100644 --- a/lib/thinking_sphinx.rb +++ b/lib/thinking_sphinx.rb @@ -96,12 +96,15 @@ module Subscribers; end require 'thinking_sphinx/utf8' require 'thinking_sphinx/wildcard' # Extended -require 'thinking_sphinx/active_record' require 'thinking_sphinx/deltas' require 'thinking_sphinx/distributed' require 'thinking_sphinx/logger' require 'thinking_sphinx/real_time' -require 'thinking_sphinx/railtie' if defined?(Rails::Railtie) +if defined?(Rails::Railtie) + require 'thinking_sphinx/railtie' +else + require 'thinking_sphinx/active_record' +end ThinkingSphinx.before_index_hooks << ThinkingSphinx::Hooks::GuardPresence diff --git a/lib/thinking_sphinx/railtie.rb b/lib/thinking_sphinx/railtie.rb index 8ba1f8583..bc9efd360 100644 --- a/lib/thinking_sphinx/railtie.rb +++ b/lib/thinking_sphinx/railtie.rb @@ -7,6 +7,7 @@ class ThinkingSphinx::Railtie < Rails::Railtie initializer 'thinking_sphinx.initialisation' do ActiveSupport.on_load(:active_record) do + require 'thinking_sphinx/active_record' ActiveRecord::Base.include ThinkingSphinx::ActiveRecord::Base end