Commit 5622a0ae82202f36c7b7d2f436e2b28bb6a8c886

Authored by Andrew Kane
1 parent 0ea6662b

Fixed scoping error

Showing 2 changed files with 19 additions and 2 deletions   Show diff stats
lib/searchkick.rb
... ... @@ -315,6 +315,23 @@ module Searchkick
315 315 end
316 316  
317 317 # private
  318 + def self.without_scope(klass)
  319 + if klass.respond_to?(:current_scope)
  320 + previous_scope = klass.current_scope
  321 + begin
  322 + klass.current_scope = nil
  323 + yield
  324 + ensure
  325 + klass.current_scope = previous_scope
  326 + end
  327 + else
  328 + klass.with_scope(nil) do
  329 + yield
  330 + end
  331 + end
  332 + end
  333 +
  334 + # private
318 335 def self.scope(model)
319 336 # safety check to make sure used properly in code
320 337 raise Error, "Cannot scope relation" if relation?(model)
... ...
lib/searchkick/model.rb
... ... @@ -79,8 +79,8 @@ module Searchkick
79 79 scoped = Searchkick.relation?(self)
80 80 # call searchkick_klass for inheritance
81 81 relation = scoped ? all : Searchkick.scope(searchkick_klass).all
82   - # prevent scope from affecting search_data
83   - unscoped do
  82 + # prevent scope from affecting search_data as well as inline jobs
  83 + Searchkick.without_scope(self) do
84 84 searchkick_index.reindex(relation, method_name, scoped: scoped, **options)
85 85 end
86 86 end
... ...