Created
December 18, 2018 06:13
-
-
Save lalitlogical/2420c4c14892d82557ba8559a7d2d986 to your computer and use it in GitHub Desktop.
searchkick mongoid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Searchkick.class_eval do | |
# Your new methods here | |
def self.load_records(records, ids) | |
records = | |
if records.respond_to?(:queryable) | |
# Mongoid 3+ | |
records.queryable.for_ids(ids) | |
elsif records.respond_to?(:primary_key) | |
# ActiveRecord | |
records.where(records.primary_key => ids) if records.primary_key | |
elsif records.respond_to?(:unscoped) && :id.respond_to?(:in) | |
# Nobrainer | |
records.unscoped.where(:id.in => ids) | |
elsif records.respond_to?(:key_column_names) | |
records.where(records.key_column_names.first => ids) | |
end | |
raise Searchkick::Error, "Not sure how to load records" if !records | |
records | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment