Skip to content

Commit

Permalink
Don't load ActiveRecord during rails initialization
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jdelStrother committed Apr 29, 2021
1 parent d1f0940 commit ea8bc34
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/thinking_sphinx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions lib/thinking_sphinx/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ea8bc34

Please sign in to comment.