-
Notifications
You must be signed in to change notification settings - Fork 53
Description
Description
The meilisearch-rails gem fails to properly handle Rails models that use a custom primary key column (other than id). The gem creates a Meilisearch index with "id" as the primary key regardless of the Rails model's actual primary key configuration, causing search results to fail when mapping back to ActiveRecord objects.
# Rails correctly identifies the primary key
Story.primary_key
# => "story_id"
# But Meilisearch uses "id" regardless
MeiliSearch::Rails.client.index("Story").get_primary_key
# => "id"Expected behavior
The Model.search returns a set of results
There are items in the min-console to search
Current behavior
I get an empty set => []
There is nothing in the mini-console
Note
If I don't set :primary_key on the config block, then I do get items in the min-console, but Story.search still returns nothing.
Environment
Operating System
OSX 15.6.1 (24G90)
Meilisearch version (./meilisearch --version):
V 1.19.1
meilisearch-rails version (bundle info meilisearch-rails):
0.16
rails version (bundle info rails):
8.0.2.1
Reproduction script:
Create a Rails model with a custom primary key:
rubyclass Story < ApplicationRecord
include MeiliSearch::Rails
self.primary_key = 'story_id' # Custom primary key column
meilisearch primary_key: :story_id do
# configuration
end
endIndex some data:
rubyStory.reindex!Attempt to search:
rubyStory.search('test query', limit: 10)