Skip to content

Unexpected behavior of index! with STI #394

@matteodepalo

Description

@matteodepalo

Description

Calling index! in a model that uses STI creates a separate index with that model's name as its name.

Steps to reproduce

My current setup has a parent model with a few sub-classes:

class Content < ActiveRecord::Base
   include AlgoliaSearch
   
   algoliasearch { ... }
end

class Post < Content
end

When calling Content.find(id).index! or Post.find(id).index! the current implementation creates a new index named Post instead of reusing the parent index Content. I've fixed this by specifying the index name:

class Content < ActiveRecord::Base
   include AlgoliaSearch
   
   algoliasearch index_name: "Content" { ... }
end

I'm also aware I can do Content.where(id: id).reindex! and this will work.

If this is expected behavior then would it be worth mentioning it in the docs?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions