Skip to content

index_name being wrong within concern and inheritence #969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kgeoir opened this issue Dec 23, 2020 · 0 comments
Open

index_name being wrong within concern and inheritence #969

kgeoir opened this issue Dec 23, 2020 · 0 comments
Labels

Comments

@kgeoir
Copy link

kgeoir commented Dec 23, 2020

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants