Skip to content

Commit a450aa6

Browse files
committed
Remove meilisearch_options[:type]
I cannot figure out why this was ever created, all tests pass with this change, it feels to me like this is just a roundabout way of shoving `self` into the hash. If there's a distinction between this logic and `self` please let me know.
1 parent 3991366 commit a450aa6

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lib/meilisearch-rails.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ class << base
8080
def meilisearch(options = {}, &block)
8181
self.meilisearch_settings = IndexSettings.new(options, &block)
8282
self.meilisearch_options = {
83-
type: model_name.to_s.constantize,
8483
per_page: meilisearch_settings.get_setting(:hitsPerPage) || 20, page: 1
8584
}.merge(options)
8685

@@ -393,12 +392,12 @@ def ms_search(query, params = {})
393392
# Since we provide a way to customize the primary_key value, `ms_pk(meilisearch_options)` may not
394393
# respond with a valid database column. The blocks below prevent that from happening.
395394
has_virtual_column_as_pk = if defined?(::Sequel::Model) && self < Sequel::Model
396-
meilisearch_options[:type].columns.map(&:to_s).exclude?(condition_key.to_s)
395+
columns.map(&:to_s).exclude?(condition_key.to_s)
397396
else
398-
meilisearch_options[:type].columns.map(&:name).map(&:to_s).exclude?(condition_key.to_s)
397+
columns.map(&:name).map(&:to_s).exclude?(condition_key.to_s)
399398
end
400399

401-
condition_key = meilisearch_options[:type].primary_key if has_virtual_column_as_pk
400+
condition_key = primary_key if has_virtual_column_as_pk
402401

403402
hit_ids = if has_virtual_column_as_pk
404403
json['hits'].map { |hit| hit[condition_key] }
@@ -410,7 +409,7 @@ def ms_search(query, params = {})
410409
# results_by_id creates a hash with the primaryKey of the document (id) as the key and doc itself as the value
411410
# {"13"=>#<Product id: 13, name: "iphone", href: "apple", tags: nil, type: nil,
412411
# description: "Puts even more features at your fingertips", release_date: nil>}
413-
results_by_id = meilisearch_options[:type].where(condition_key => hit_ids).index_by do |hit|
412+
results_by_id = where(condition_key => hit_ids).index_by do |hit|
414413
ms_primary_key_of(hit)
415414
end
416415

0 commit comments

Comments
 (0)