Skip to content

Commit 006108e

Browse files
authored
[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 62191f8 commit 006108e

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

elasticsearch-model/README.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -732,13 +732,8 @@ module and its submodules for technical information.
732732

733733
The module provides a common `settings` method to customize various features.
734734

735-
At the moment, the only supported setting is `:inheritance_enabled`, which makes the class receiving the module
736-
respect index names and document types of a super-class, eg. in case you're using "single table inheritance" (STI)
737-
in Rails:
738-
739-
```ruby
740-
Elasticsearch::Model.settings[:inheritance_enabled] = true
741-
```
735+
Before version 7.0.0 of the gem, the only supported setting was `:inheritance_enabled`. This setting has been deprecated
736+
and removed.
742737

743738
## Development and Community
744739

@@ -756,6 +751,15 @@ curl -# https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticse
756751
SERVER=start TEST_CLUSTER_COMMAND=$PWD/tmp/elasticsearch-1.0.0.RC1/bin/elasticsearch bundle exec rake test:all
757752
```
758753

754+
### Single Table Inheritance support
755+
756+
Versions < 7.0.0 of this gem supported inheritance-- more specifically, `Single Table Inheritance`. With this feature,
757+
settings on a parent model could be inherited by a child model leading to different model documents being indexed
758+
into the same Elasticsearch index. This feature depended on the ability to set a `type` for a document in Elasticsearch.
759+
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)
760+
so this gem has also removed support as it encourages an anti-pattern. Please save different model documents in
761+
separate indices or implement an artificial `type` field manually in each document.
762+
759763
## License
760764

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

elasticsearch-model/lib/elasticsearch/model.rb

+15-8
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,6 @@ class << self
121121
Registry.add(base) if base.is_a?(Class)
122122
end
123123

124-
# Access the module settings
125-
#
126-
def self.settings
127-
@settings ||= {}
128-
end
129-
130124
module ClassMethods
131125
# Get the client common for all models
132126
#
@@ -183,7 +177,7 @@ def search(query_or_payload, models=[], options={})
183177
# @note Inheritance is disabled by default.
184178
#
185179
def inheritance_enabled
186-
@inheritance_enabled ||= false
180+
@settings[:inheritance_enabled] ||= false
187181
end
188182

189183
# Enable inheritance of index_name and document_type
@@ -193,8 +187,21 @@ def inheritance_enabled
193187
# Elasticsearch::Model.inheritance_enabled = true
194188
#
195189
def inheritance_enabled=(inheritance_enabled)
196-
@inheritance_enabled = inheritance_enabled
190+
warn STI_DEPRECATION_WARNING
191+
@settings[:inheritance_enabled] = inheritance_enabled
192+
end
193+
194+
# Access the module settings
195+
#
196+
def settings
197+
@settings ||= {}
197198
end
199+
200+
private
201+
202+
STI_DEPRECATION_WARNING = "DEPRECATION WARNING: Support for Single Table Inheritance (STI) is deprecated " +
203+
"and will be removed in version 7.0.0.\nPlease save different model documents in separate indices and refer " +
204+
"to the Elasticsearch documentation for more information.".freeze
198205
end
199206
extend ClassMethods
200207

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ module ::MyNamespace
6161
end
6262

6363
around(:all) do |example|
64-
original_value = Elasticsearch::Model.settings[:inheritance_enabled]
65-
Elasticsearch::Model.settings[:inheritance_enabled] = true
64+
original_value = Elasticsearch::Model.inheritance_enabled
65+
Elasticsearch::Model.inheritance_enabled = true
6666
example.run
67-
Elasticsearch::Model.settings[:inheritance_enabled] = original_value
67+
Elasticsearch::Model.inheritance_enabled = original_value
6868
end
6969

7070

0 commit comments

Comments
 (0)