Skip to content

index_name being wrong within concern and inheritence #969

Open
@kgeoir

Description

@kgeoir

Hello,
I have an issue with index_name not beging set properly:

I have a concern with my index definition:

module Searchable
      extend ActiveSupport::Concern

    included do
      include Elasticsearch::Model
      include Elasticsearch::Model::Callbacks

      index_name "my_index_#{Rails.env}"
      end
  end

This concern is used in one AR model using sti this way:

class SuperKlass < ApplicationRecord
  include Searchable
  end

And this class has childs like this one:

class Child1 < SuperKlass
  end

When I try to index, I get error, index child1 does not exist but its index should be "my_index_#{Rails.env}"... In my rails console, I can see that index_name is not properly set:

  2.7.0 :001 > Child1.index_name
 => "child1"

2.7.0 :002 > SuperKlass.index_name
 => "my_index_development"

I try to include the concern in all childs but still it does not work.... I am now adding index_name call in all childs but that's not the purpose of inheritence.... Any idea?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions