Commit 00d58aa540869deee8c1f96f4d809e554aab4354

Authored by Andrew Kane
1 parent 1114f61d

Improved load_records code [skip ci]

Showing 1 changed file with 11 additions and 12 deletions   Show diff stats
lib/searchkick.rb
... ... @@ -266,21 +266,20 @@ module Searchkick
266 266 end
267 267  
268 268 # private
269   - def self.load_records(records, ids)
270   - records =
271   - if records.respond_to?(:primary_key)
272   - # ActiveRecord
273   - records.where(records.primary_key => ids) if records.primary_key
274   - elsif records.respond_to?(:queryable)
275   - # Mongoid 3+
276   - records.queryable.for_ids(ids)
277   - elsif records.respond_to?(:key_column_names)
278   - records.where(records.key_column_names.first => ids)
  269 + def self.load_records(relation, ids)
  270 + relation =
  271 + if relation.respond_to?(:primary_key)
  272 + primary_key = relation.primary_key
  273 + raise Error, "Need primary key to load records" if !primary_key
  274 +
  275 + relation.where(primary_key => ids)
  276 + elsif relation.respond_to?(:queryable)
  277 + relation.queryable.for_ids(ids)
279 278 end
280 279  
281   - raise Searchkick::Error, "Not sure how to load records" if !records
  280 + raise Error, "Not sure how to load records" if !relation
282 281  
283   - records
  282 + relation
284 283 end
285 284  
286 285 # private
... ...