You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
If you provide a custom primary key method and also specify attributes other than the real primary key of the model in the meilisearch block, the documents in the meilisearch instance will not contain the model's real primary key and therefore cannot map to database records.
Expected behavior
MeiliSearch still includes ID in its documents and fetching does not fail.
Reproduction script
require'bundler/inline'gemfiledogem"rails","~> 7.1.3"gem"sqlite3","~> 1.4"gem"meilisearch-rails","~> 0.11.1"endMeiliSearch::Rails.configuration={meilisearch_url: ENV.fetch('MEILISEARCH_HOST','http://localhost:7700'),meilisearch_api_key: ENV.fetch('MEILISEARCH_API_KEY','masterKey')}MeiliSearch::Rails.client.delete_index'dogs'MeiliSearch::Rails.client.delete_index'cats'sleep0.1FileUtils.rm('data.sqlite3')ifFile.exist?('data.sqlite3')require'active_record'ActiveRecord::Base.establish_connection('adapter'=>defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3','database'=>'data.sqlite3','pool'=>5,'timeout'=>5000)ActiveRecord::Schema.definedocreate_table(:dogs){ |t| t.string:name}create_table(:cats){ |t| t.string:name}end# With custom primary keyclassDog < ActiveRecord::BaseincludeMeiliSearch::Railsmeilisearchindex_uid: 'dogs',primary_key: :ms_iddoattribute:nameenddefms_id"dog_#{id}"endend# Without custom primary keyclassCat < ActiveRecord::BaseincludeMeiliSearch::Railsmeilisearchindex_uid: 'cats'doattribute:nameendendDog.createname: 'spikey'Cat.createname: 'fluffy'sleep0.5pDog.search'spikey'# Will return nothing# []pDog.index.search('spikey')['hits']# Documents without IDs# [{"ms_id"=>"dog_2", "name"=>"spikey"}]pCat.search'fluffy'# Returns a cat correctly# [#<Cat id: 1, name: "fluffy">]pCat.index.search('fluffy')['hits']# Documents still have IDs# [{"id"=>"1", "name"=>"fluffy"}]
The text was updated successfully, but these errors were encountered:
Description
If you provide a custom primary key method and also specify attributes other than the real primary key of the model in the
meilisearch
block, the documents in the meilisearch instance will not contain the model's real primary key and therefore cannot map to database records.Expected behavior
MeiliSearch still includes ID in its documents and fetching does not fail.
Reproduction script
The text was updated successfully, but these errors were encountered: