Skip to content

Commit

Permalink
Wait to load PgSearch::Document until after ActiveRecord has loaded
Browse files Browse the repository at this point in the history
Loading the PgSearch::Document model without waiting for ActiveRecord to
load can cause problems because it causes ActiveRecord to pull
configuration into ActiveRecord::Base before the initializers get
loaded. This means ActiveRecord::Base could accidentally have inaccurate
configuration.

The fix for this is to wait until ActiveRecord has fully loaded before
requiring the model.

ref: rails/rails#23589
  • Loading branch information
lleger committed Aug 23, 2016
1 parent f1da2a1 commit 4a3e0f0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/pg_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,8 @@ def message
end
end

require "pg_search/document"
ActiveSupport.on_load(:active_record) do
require "pg_search/document"
end

require "pg_search/railtie" if defined?(Rails)

0 comments on commit 4a3e0f0

Please sign in to comment.