brewster / elastictastic

Object-document mapper and lightweight API adapter for ElasticSearch
MIT License
88 stars 13 forks source link

Can't update record #29

Closed mrcasals closed 11 years ago

mrcasals commented 11 years ago

I cannot update an element:

product = Product.find(1)
product.name # => "Book"
product_attributes = {"name":"Magazine")
product.update(product_attributes)
product.save
product.name # => "Book"
Product.find(2).name # => "Book"

What am I doing wrong, here? :(

I found something that might imply this is an elastictastic bug: the Persistence module has an update method, but it does not seem to use the options I send to it:

https://github.com/brewster/elastictastic/blob/master/lib/elastictastic/persistence.rb#L54-L56

outoftime commented 11 years ago

The #update method is not part of the public API (I'm surprised you're able to call it in the above example, since its visibility is protected). The method you're looking for is #attributes=, as in:

product.attributes = product_attributes
product.save
mrcasals commented 11 years ago

Perfect, thanks! :)