Skip to content

Indexing records with STI models #436

@cbaykam

Description

@cbaykam

Description

When we try to index records within the child model of an STI relation, the primary_key: :id option is ignored.

Within the model when we define the meilisearch block like below

class Novel < Book do 
  include Meilisearch::Rails
  extend Pagy::Meilisearch
  
  meilisearch primary_key: :id do 
   .... 
  end
end  

And try to index the Novels from the rails console :

> client = Meilisearch::Client.new(ENV.fetch('MEILISEARCH_HOST', 'http://localhost:7700'), ENV.fetch('MEILISEARCH_API_KEY', ""), { timeout: 120 })
> Novel.reindex!  
> client.tasks 

We get an error message:

"The primary key inference failed as the engine found 2 fields ending with `id` in their names: 'id' and 'category_id'. Please specify the primary key manually using the `primaryKey` query parameter.",

Expected behavior

meilisearch primary_key: :id do should be taken into account.

Current behavior

Screenshots or logs

Environment

Operating System [e.g. Debian GNU/Linux] (cat /etc/*-release | head -n1):

Meilisearch version (./meilisearch --version): 1.16

meilisearch-rails version (bundle info meilisearch-rails): meilisearch-rails (0.16.0)

rails version (bundle info rails): rails (8.0.2)

Reproduction script:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions