Skip to content
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

[MODEL] Clear type cache when reloading and ensure model list is unique #888

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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: 11 additions & 0 deletions elasticsearch-model/lib/elasticsearch/model/adapters/multiple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion elasticsearch-model/lib/elasticsearch/model/multimodel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down