diff --git a/elasticsearch-model/lib/elasticsearch/model/adapters/multiple.rb b/elasticsearch-model/lib/elasticsearch/model/adapters/multiple.rb index b4df631f4..80c34c856 100644 --- a/elasticsearch-model/lib/elasticsearch/model/adapters/multiple.rb +++ b/elasticsearch-model/lib/elasticsearch/model/adapters/multiple.rb @@ -28,6 +28,17 @@ module Multiple Adapter.register self, lambda { |klass| klass.is_a? Multimodel } module Records + + def self.included(base) + base.extend(ClassMethods) + end + + module ClassMethods + def __clear_types! + @@__types = nil + end + end + # Returns a collection of model instances, possibly of different classes (ActiveRecord, Mongoid, ...) # # @note The order of results in the Elasticsearch response is preserved diff --git a/elasticsearch-model/lib/elasticsearch/model/multimodel.rb b/elasticsearch-model/lib/elasticsearch/model/multimodel.rb index 2c2306274..5af7d0ce0 100644 --- a/elasticsearch-model/lib/elasticsearch/model/multimodel.rb +++ b/elasticsearch-model/lib/elasticsearch/model/multimodel.rb @@ -48,7 +48,12 @@ def self.all # Adds a model to the registry # def add(klass) - @models << klass + if i = @models.index { |_class| _class.name == klass.name } + @models[i] = klass + Model::Multiple.__clear_types! + else + @models << klass + end end # Returns a copy of the registered models