Commit 9703312f8abe09fc47dd1e4b23c5ceaac9ac3105

Authored by Jeroen Visser
1 parent c482dbf5

Update eager_loading logic to match nobrainer >v0.20

The commit (https://github.com/nviennot/nobrainer/commit/d9f27b002e151cda141220e4111570acb2c35e45)
changed the name of preload to eager_load and preload is now deprecated.

This change will use the newer versions for projects using the newer
version.
Showing 1 changed file with 6 additions and 2 deletions   Show diff stats
lib/searchkick/results.rb
... ... @@ -181,7 +181,11 @@ module Searchkick
181 181 if options[:includes]
182 182 records =
183 183 if defined?(NoBrainer::Document) && records < NoBrainer::Document
184   - records.preload(options[:includes])
  184 + if Gem.loaded_specs["nobrainer"].version >= Gem::Version.new("0.21")
  185 + records.eager_load(options[:includes])
  186 + else
  187 + records.preload(options[:includes])
  188 + end
185 189 else
186 190 records.includes(options[:includes])
187 191 end
... ... @@ -196,7 +200,7 @@ module Searchkick
196 200 elsif records.respond_to?(:queryable)
197 201 # Mongoid 3+
198 202 records.queryable.for_ids(ids)
199   - elsif records.respond_to?(:unscoped) && records.all.respond_to?(:preload)
  203 + elsif records.respond_to?(:unscoped) && [:preload, :eager_load].any? { |m| records.all.respond_to?(m) }
200 204 # Nobrainer
201 205 records.unscoped.where(:id.in => ids)
202 206 else
... ...