Skip to content

Commit afaf918

Browse files
committed
[MODEL] Add warning and documentation about STI support being deprecated (elastic#895)
* [MODEL] Add warning and documentation about STI support being deprecated * [MODEL] Minor change to STI deprecation warning * [MODEL] Freeze string constant depreaction warning
1 parent 39a3022 commit afaf918

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

elasticsearch-model/README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -724,13 +724,8 @@ module and its submodules for technical information.
724724

725725
The module provides a common `settings` method to customize various features.
726726

727-
At the moment, the only supported setting is `:inheritance_enabled`, which makes the class receiving the module
728-
respect index names and document types of a super-class, eg. in case you're using "single table inheritance" (STI)
729-
in Rails:
730-
731-
```ruby
732-
Elasticsearch::Model.settings[:inheritance_enabled] = true
733-
```
727+
Before version 7.0.0 of the gem, the only supported setting was `:inheritance_enabled`. This setting has been deprecated
728+
and removed.
734729

735730
## Development and Community
736731

@@ -748,6 +743,15 @@ curl -# https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticse
748743
SERVER=start TEST_CLUSTER_COMMAND=$PWD/tmp/elasticsearch-1.0.0.RC1/bin/elasticsearch bundle exec rake test:all
749744
```
750745

746+
### Single Table Inheritance support
747+
748+
Versions < 7.0.0 of this gem supported inheritance-- more specifically, `Single Table Inheritance`. With this feature,
749+
settings on a parent model could be inherited by a child model leading to different model documents being indexed
750+
into the same Elasticsearch index. This feature depended on the ability to set a `type` for a document in Elasticsearch.
751+
The Elasticsearch team has deprecated support for `types`, as is described [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html)
752+
so this gem has also removed support as it encourages an anti-pattern. Please save different model documents in
753+
separate indices or implement an artificial `type` field manually in each document.
754+
751755
## License
752756

753757
This software is licensed under the Apache 2 license, quoted below.

elasticsearch-model/lib/elasticsearch/model.rb

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,6 @@ class << self
131131
end
132132
end
133133

134-
# Access the module settings
135-
#
136-
def self.settings
137-
@settings ||= {}
138-
end
139-
140134
module ClassMethods
141135
# Get the client common for all models
142136
#
@@ -193,7 +187,7 @@ def search(query_or_payload, models=[], options={})
193187
# @note Inheritance is disabled by default.
194188
#
195189
def inheritance_enabled
196-
@inheritance_enabled ||= false
190+
@settings[:inheritance_enabled] ||= false
197191
end
198192

199193
# Enable inheritance of index_name and document_type
@@ -203,8 +197,21 @@ def inheritance_enabled
203197
# Elasticsearch::Model.inheritance_enabled = true
204198
#
205199
def inheritance_enabled=(inheritance_enabled)
206-
@inheritance_enabled = inheritance_enabled
200+
warn STI_DEPRECATION_WARNING
201+
@settings[:inheritance_enabled] = inheritance_enabled
202+
end
203+
204+
# Access the module settings
205+
#
206+
def settings
207+
@settings ||= {}
207208
end
209+
210+
private
211+
212+
STI_DEPRECATION_WARNING = "DEPRECATION WARNING: Support for Single Table Inheritance (STI) is deprecated " +
213+
"and will be removed in version 7.0.0.\nPlease save different model documents in separate indices and refer " +
214+
"to the Elasticsearch documentation for more information.".freeze
208215
end
209216
extend ClassMethods
210217

elasticsearch-model/spec/elasticsearch/model/naming_inheritance_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ class ::Animal < ::TestBase
2020
document_type "mammal"
2121
end
2222

23-
class ::Dog < ::Animal
23+
around(:all) do |example|
24+
original_value = Elasticsearch::Model.inheritance_enabled
25+
Elasticsearch::Model.inheritance_enabled = true
26+
example.run
27+
Elasticsearch::Model.inheritance_enabled = original_value
2428
end
2529

2630
module ::MyNamespace

0 commit comments

Comments
 (0)