-
Notifications
You must be signed in to change notification settings - Fork 801
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
Use parent's index_name and document_type from child models #344
Conversation
Interesting idea! Couple of notes, I'm travelling these days: we definitely need unit tests for this, and this is probably related to all the "single-table inheritance" (STI) issues being reported for Rails integration. Can you look at them? It would be great to have integration tests covering these... |
Hello, I'll need some time to process the patch -- there are couple of things which stick out, for instance, we deliberately don't add |
Suppose there are three models: class Company < ActiveRecord::Base include Elasticsearch::Model end class TechCompany < Company; end class TradingCompany < Company; end then previously they respond to "document_type" as follows: Company.document_type #=> 'company' TechCompany.document_type #=> 'tech_company' TradingCompany.document_type #=> 'trading_company' This commit changes them as: Company.document_type #=> 'company' TechCompany.document_type #=> 'company' TradingCompany.document_type #=> 'company' They respond to "index_name" in the same manner.
Hi, sorry for my late reply. I miss understood the code base - I thought elasticsearch-model is used by only elasticsearch-rails. elasticsearch-persistence also uses it!
As I noted above, I added the dependency due to my wrong understanding. I've just removed it and updated the patch. I want to write tests for this as soon as possible. (I'm busy now to write an article for Japanese famous tech magazine about "How to use elasticsearch in Ruby". It refers both this repository and elasticsearch-ruby 😏 ) |
Hi, I finished the work last weekend. I check the failing tests and referred issues. |
I'm assuming these two are related? #332 |
So, I tested out this change set and the issue with this approach is that it ignores the |
This patch adds support for inheriting index_name and document_type on an opt-in basis: Elasticsearch::Model.inheritance_enabled = true class Animal < ActiveRecord::Base document_type 'mammal' index_name 'mammals' end class Dog < Animal end Animal.document_type # 'mammal' Animal.index_name # 'mammals' Dog.document_type # 'mammal' Dog.index_name # 'mammals' Closes #332 Related: #28, #92, #170, #344
Suppose there are three models:
then previously they respond to "document_type" as follows:
This commit changes them as:
So, we can use search scope like this: