From 0863f36848050c52145286f42b4265f18a58b73e Mon Sep 17 00:00:00 2001 From: Yury Kaliada Date: Mon, 9 Jun 2014 15:50:44 +0300 Subject: [PATCH] Fix changed attributes matching If I define `as_indexed_json` function to return symbol-keyed hash then the changes will not be detected because: ``` def as_indexed_json {name: name} end as_indexed_json.keys.include? 'name' #=> false ``` Thus I recommend to compare string variants. --- elasticsearch-model/lib/elasticsearch/model/indexing.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elasticsearch-model/lib/elasticsearch/model/indexing.rb b/elasticsearch-model/lib/elasticsearch/model/indexing.rb index 360b8ea85..948c7b62a 100644 --- a/elasticsearch-model/lib/elasticsearch/model/indexing.rb +++ b/elasticsearch-model/lib/elasticsearch/model/indexing.rb @@ -336,7 +336,7 @@ def delete_document(options={}) def update_document(options={}) if changed_attributes = self.instance_variable_get(:@__changed_attributes) attributes = if respond_to?(:as_indexed_json) - changed_attributes.select { |k,v| self.as_indexed_json.keys.include? k } + changed_attributes.select { |k,v| self.as_indexed_json.keys.map(&:to_s).include? k.to_s } else changed_attributes end