Skip to content

Use parent's index_name and document_type from child models #344

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions elasticsearch-model/lib/elasticsearch/model/naming.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def index_name name=nil, &block
if @index_name.respond_to?(:call)
@index_name.call
else
@index_name || self.model_name.collection.gsub(/\//, '-')
@index_name || self.base_model_name.collection.gsub(/\//, '-')
end
end

Expand All @@ -58,7 +58,7 @@ def index_name=(name)
# Article.document_type "my-article"
#
def document_type name=nil
@document_type = name || @document_type || self.model_name.element
@document_type = name || @document_type || self.base_model_name.element
end


Expand All @@ -69,6 +69,13 @@ def document_type name=nil
def document_type=(name)
@document_type = name
end

private

# Get the base class's model_name
def base_model_name
respond_to?(:base_class) ? base_class.model_name : model_name
end
end

module InstanceMethods
Expand Down